-module(ebb_pipe_fsm). -include("../include/ebb_prim.hrl"). %% API -export([start_link/3]). %%==================================================================== %% API %%==================================================================== %%-------------------------------------------------------------------- %% Function: start_link() -> {ok,Pid} | ignore | {error,Error} %% Description:Creates a gen_fsm process which calls Module:init/1 to %% initialize. To ensure a synchronized start-up procedure, this function %% does not return until Module:init/1 has returned. %%-------------------------------------------------------------------- start_link(#pipe{ops=Ops}, Run, Receiver) when is_function(Run), is_pid(Receiver) -> start_chain(lists:reverse(Ops), Run, Receiver). start_chain([Op1|Ops], Run, Receiver) -> lists:foldl(fun(Op, {ok, Target}) -> Out = ebb_prim:out_arity(Op), {ok, Link} = ebb_chain_fsm:start_link(Out, Target), Run(Op, Link) end, Run(Op1, Receiver), Ops).