collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

How to halt execution of the perform without failure? #118

Closed zedtux closed 7 years ago

zedtux commented 7 years ago

As of today, in the case I want to halt the execution of the perform for any other reason than a failure, I'm using context.fail! (so like a return in "normal" Ruby).

Even if this doesn't looks good to me, I was then excepting doing a context.success! in order to return from my interactor but doesn't work.

All in all, something seems missing to me: Halting an interactor, not because of an error, but because it shouldn't go further.

Thank you in advance.

gee-forr commented 7 years ago

I'd like to know the answer to this one myself :)

Light Service has the concept of context.skip_all! for ending a series of interactions in an organiser whilst still keeping the status as successful. Would be handy to have that here too.

laserlemon commented 7 years ago

Closing in anticipation of Interactor 4.0. Please see this comment for more details.

zedtux commented 7 years ago

Thank you @laserlemon for this update 👍

mengqing commented 7 years ago

I normally just early return if I want the interactor to halt from proceeding

christopherstyles commented 6 years ago

I normally just early return if I want the interactor to halt from proceeding

@mengqing I’m curious how you do this? Simply returning from the call method doesn’t seem to skip subsequent interactors for me.

gee-forr commented 6 years ago

@christopherstyles - @mengqing might just mean he's only using 1 interactor at a time and isn't using organisers?

One thing you could try do in the meantime whilst waiting for interactor 4.0 to land, is to add a flag into the context. Something like context.skip_rest = true.

You could then have an around block that conditionally executes the interactor based on that value:

around do |interactor|
  interactor.call unless interactor.context.skip_rest
end

I don't actually know if this will work, as I haven't tested it. Let me know if it helps you.

christopherstyles commented 6 years ago

Thanks @gee-forr! One quick change to the unless, and it works great. Much appreciated 👍


around do |interactor|
  interactor.call unless context.skip
end