ebb_pipe_fsm.erl 1010 B

123456789101112131415161718192021222324252627
  1. -module(ebb_pipe_fsm).
  2. -include("../include/ebb_prim.hrl").
  3. %% API
  4. -export([start_link/3]).
  5. %%====================================================================
  6. %% API
  7. %%====================================================================
  8. %%--------------------------------------------------------------------
  9. %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
  10. %% Description:Creates a gen_fsm process which calls Module:init/1 to
  11. %% initialize. To ensure a synchronized start-up procedure, this function
  12. %% does not return until Module:init/1 has returned.
  13. %%--------------------------------------------------------------------
  14. start_link(#pipe{ops=Ops}, Run, Receiver)
  15. when is_function(Run), is_pid(Receiver) ->
  16. start_chain(lists:reverse(Ops), Run, Receiver).
  17. start_chain([Op1|Ops], Run, Receiver) ->
  18. lists:foldl(fun(Op, {ok, Target}) ->
  19. Out = ebb_prim:out_arity(Op),
  20. {ok, Link} = ebb_chain_fsm:start_link(Out, Target),
  21. Run(Op, Link)
  22. end,
  23. Run(Op1, Receiver), Ops).