Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
niahoo opened this issue Jul 21, 2017 · 0 comments

Comments

@niahoo
Copy link

niahoo commented Jul 21, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant