Closed zedtux closed 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.
Closing in anticipation of Interactor 4.0. Please see this comment for more details.
Thank you @laserlemon for this update 👍
I normally just early return if I want the interactor to halt from proceeding
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.
@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.
Thanks @gee-forr! One quick change to the unless
, and it works great. Much appreciated 👍
around do |interactor|
interactor.call unless context.skip
end
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 areturn
in "normal" Ruby).Even if this doesn't looks good to me, I was then excepting doing a
context.success!
in order toreturn
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.
context.halt!
orcontext.stop!
which will halt the execution andcontext.success?
should returntrue
in this case.Thank you in advance.