gen_server
Vance Shipley
vances@REDACTED
Wed Dec 17 00:55:44 CET 2003
On Mon, Dec 15, 2003 at 11:10:15PM +0000, Sean Hinde wrote:
}
} Alternatively, and what I normally do, is to store the From ref and the
} Pid of the spawned process in an ets table owned by the main gen_server
Ah but that's cheating isn't it? :)
Here's what I do:
-behaviour(gen_server).
init(_) ->
{ok, gb_trees:empty()}.
handle_call(Fun, From, State) ->
Pid = proc_lib:spawn(Fun),
{noreply, gb_trees:insert(Pid, From)}.
handle_info({Pid, Result}, State) ->
gen_server:reply(gb_trees:get(Pid, State), Result),
{noreply, gb_trees:delete(Pid, State)}.
-Vance
More information about the erlang-questions
mailing list