uwiger / gproc

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

Is there a way to be notified whenever a process registers a property/resource ? #138

Open niahoo opened 7 years ago

niahoo commented 7 years ago

Hi,

I'm sorry this is not really an issue, but an "How to" question.

It's unclear to me if this is actually feasible :

(This is just an example, I don't care about github)

What I would like to do is that some processes register properties in gproc to be notified about events, like {p, l, github_issues} with a value set to "uwiger/gproc".

But I need a process to be notified when a github_issues key is registered, to be able to get the value and then check the github API from time to time and publish news in gproc. I need to be notified when a process unreg() to stop looking at a repository.

I could just wait for reg/unreg messages and each time ask all the values from gproc and diff with my current values.

At the moment, what I do is having a module doing the registration and a gen server that monitors the values.


-module(scrap_github).

monitor_issues(Repo) ->
    gen_server:call(?SERVER, {ensure_that_you_are_monitoring_this_stuff, issues, Repo}),
    gproc:reg({p, l, github_issues}, Repo),
    ok.

(edit: with a counter in the gen server, for unregistrations, to behave like on_zero feature).

It feels like a hack, is there a better way with gproc ?

Thank you.