emqx / ecpool

Erlang Connection/Client Pool Library
MIT License
30 stars 20 forks source link

Callback connect state #4

Closed turtleDeng closed 7 years ago

turtleDeng commented 7 years ago

For some reason, I create a process must pass a process registered name. However, the use of ecpool to manage the process and found that the need to import process name will be very troublesome. Can in the callback time, return an Opts, so I can start a process each time when the record in the Opts inside. E.g

connect(Opts) ->
    State = proplists:get_value(state, Opts, 0),
    PoolName = list_to_atom(lists:concat(["client", State])),
    {ok, Pid} = brod:start_client([{"127.0.0.1", 9092}], PoolName),
    {ok, Pid, lists:keyreplace(state, 1, Opts, {state, State+1})}.