Last active
August 29, 2015 14:05
-
-
Save egobrain/5779fd5284de8a9de2b4 to your computer and use it in GitHub Desktop.
Thirdparty gproc sub.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(pub_sub). | |
-export([ | |
sub/1, | |
sub/2, | |
pub/2 | |
]). | |
sub(Property) -> | |
sub(Property, self()). | |
sub(Property, Pid) -> | |
Key = {p, l, Property}, | |
Value = undefined, | |
case gproc_lib:insert_reg(Key, Value, Pid, l) of | |
false -> throw({gproc_error, badarg}); | |
true -> monitor_pid(Pid) | |
end. | |
monitor_pid(Pid) -> | |
case ets:insert_new(gproc, {{Pid,l}}) of | |
false -> true; | |
true -> | |
gen_server:cast(gproc, {monitor_me,Pid}), | |
true | |
end. | |
pub(Property, Msg) -> | |
gproc:send({p, l, Property}, Msg). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment