uwiger / gproc

Extended process registry for Erlang
Apache License 2.0
1.07k stars 232 forks source link

gproc_pool usage #62

Closed djnym closed 10 years ago

djnym commented 10 years ago

When trying to use gproc_pool, I'm finding myself having to jump through some hoops and am not sure if I'm doing something wrong or not, so opening an issue so if there is one it can be tracked.

First off, the documentation for gproc_pool:new/1,3 say they return 'true', but they actually return 'ok'.

Next the pick/1,2 functions seem to return an internal representation. For an example,

Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> application:start(gproc).
ok
2> gproc_pool:new (pool).
ok
3> gproc_pool:add_worker (pool, a).
1
4> gproc_pool:connect_worker (pool, a).
true
5> gproc_pool:add_worker (pool, b).
2
6> gproc_pool:connect_worker (pool, b).
true
7> gproc_pool:pick (pool).
{n,l,[gproc_pool,pool,1,a]}
8>

This means I can't do the natural sort of thing like

gen_server:cast (gproc_pool:whereis_worker (gproc_pool:pick (pool)), Msg)

but instead need to do something convoluted like

{n,l,[_,_,_,Id]} = gproc_pool:pick (pool),
gen_server:cast (gproc_pool:whereis_worker (Id), Msg)

which while not bad, seems like a poor API, but I might be missing something completely, so please correct me if there is a better way to do this? Oh, actually, I might have just found it, looks like you can do

gen_server:cast (gproc:where (gproc_pool:pick (pool)), Msg)

is that the expected way to use gproc_pool, or would it be better to have pick/1,3 (or maybe a wrapper pick_worker/1,3) which does the unboxing and returns a worker id. It would make the gproc_pool API a bit cleaner if you didn't actually have to call gproc functions in general use.

uwiger commented 10 years ago

Hi Anthony.

I guess I'm surprised that people are actually using gproc_pool :) But if it has the potential of being useful, let's ensure that the API is convenient.

uwiger commented 10 years ago

Comments?

djnym commented 10 years ago

The change looks good to me. I like that pick_worker just returns the pid that helps since I can just pick and send.

uwiger commented 10 years ago

Ok, good. I merged the PR. Thanks.