zorbash / opus

A framework for pluggable business logic components
MIT License
354 stars 21 forks source link

question: is there any equivalent link+tee function ? #23

Closed r8code closed 4 years ago

r8code commented 4 years ago

I want to pipe to the other opus pipeline but with behavior like tee , is there any function like that , or am I doing wrong ? btw thx for this great library , it's like simplified saga pattern

zorbash commented 4 years ago

Hi @r8code !

So what I think you're trying to achieve is:

defmodule CreateUserPipeline
  use Opus.Pipeline

  step :persist
  link UserNotificationPipeline
  step :respond
end

and in the code above, you don't want to halt the pipeline when UserNotificationPipeline completes with {:error, _}. Is this correct?

Well, at the moment the link stage is a step which accepts a pipeline module. You'd have to do something like:

defmodule CreateUserPipeline
  use Opus.Pipeline

  step :persist
  tee :notify_user, with: &UserNotificationPipeline.call/1
  step :respond
end

or even write a more verbose function emulating this behaviour. However, I see that configuring the behaviour or link can be very convenient.

r8code commented 4 years ago

Exactly what I want to achieve , Thx a lot