Skip to content

Commit

Permalink
gproc_ps selects must wrap Event in output
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger authored and RJ committed Jul 9, 2012
1 parent 9a0e7e4 commit ffe4140
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
23 changes: 21 additions & 2 deletions doc/gproc_ps.md
Expand Up @@ -69,7 +69,7 @@ counters to good effect.
##Function Index## ##Function Index##




<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#create_single-2">create_single/2</a></td><td>Creates a single-shot subscription entry for Event.</td></tr><tr><td valign="top"><a href="#delete_single-2">delete_single/2</a></td><td>Deletes the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#disable_single-2">disable_single/2</a></td><td>Disables the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#enable_single-2">enable_single/2</a></td><td>Enables the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#list_singles-2">list_singles/2</a></td><td>Lists all single-shot subscribers of Event, together with their status.</td></tr><tr><td valign="top"><a href="#list_subs-2">list_subs/2</a></td><td>List the pids of all processes subscribing to <code>Event</code></td></tr><tr><td valign="top"><a href="#publish-3">publish/3</a></td><td>Publish the message <code>Msg</code> to all subscribers of <code>Event</code></td></tr><tr><td valign="top"><a href="#subscribe-2">subscribe/2</a></td><td>Subscribe to events of type <code>Event</code></td></tr><tr><td valign="top"><a href="#tell_singles-3">tell_singles/3</a></td><td>Publish <code>Msg</code> to all single-shot subscribers of <code>Event</code></td></tr><tr><td valign="top"><a href="#unsubscribe-2">unsubscribe/2</a></td><td>Remove subscribtion created using <code>subscribe(Scope, Event)</code></td></tr></table> <table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#create_single-2">create_single/2</a></td><td>Creates a single-shot subscription entry for Event.</td></tr><tr><td valign="top"><a href="#delete_single-2">delete_single/2</a></td><td>Deletes the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#disable_single-2">disable_single/2</a></td><td>Disables the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#enable_single-2">enable_single/2</a></td><td>Enables the single-shot subscription for Event.</td></tr><tr><td valign="top"><a href="#list_singles-2">list_singles/2</a></td><td>Lists all single-shot subscribers of Event, together with their status.</td></tr><tr><td valign="top"><a href="#list_subs-2">list_subs/2</a></td><td>List the pids of all processes subscribing to <code>Event</code></td></tr><tr><td valign="top"><a href="#notify_single_if_true-4">notify_single_if_true/4</a></td><td>Create/enable a single subscription for event; notify at once if F() -> true.</td></tr><tr><td valign="top"><a href="#publish-3">publish/3</a></td><td>Publish the message <code>Msg</code> to all subscribers of <code>Event</code></td></tr><tr><td valign="top"><a href="#subscribe-2">subscribe/2</a></td><td>Subscribe to events of type <code>Event</code></td></tr><tr><td valign="top"><a href="#tell_singles-3">tell_singles/3</a></td><td>Publish <code>Msg</code> to all single-shot subscribers of <code>Event</code></td></tr><tr><td valign="top"><a href="#unsubscribe-2">unsubscribe/2</a></td><td>Remove subscribtion created using <code>subscribe(Scope, Event)</code></td></tr></table>




<a name="functions"></a> <a name="functions"></a>
Expand Down Expand Up @@ -216,7 +216,26 @@ Lists all single-shot subscribers of Event, together with their status<a name="l


List the pids of all processes subscribing to `Event` List the pids of all processes subscribing to `Event`


This function uses `gproc:select/2` to find all properties indicating a subscription.<a name="publish-3"></a> This function uses `gproc:select/2` to find all properties indicating a subscription.<a name="notify_single_if_true-4"></a>

###notify_single_if_true/4##




<pre>notify_single_if_true(Scope::<a href="#type-scope">scope()</a>, Event::<a href="#type-event">event()</a>, F::fun(() -> boolean()), Msg::<a href="#type-msg">msg()</a>) -> ok</pre>
<br></br>






Create/enable a single subscription for event; notify at once if F() -> true

This function is a convenience function, wrapping a single-shot pub/sub around a
user-provided boolean test. `Msg` should be what the publisher will send later, if the
immediate test returns `false`.<a name="publish-3"></a>


###publish/3## ###publish/3##


Expand Down
10 changes: 9 additions & 1 deletion src/gproc_ps.erl
Expand Up @@ -177,10 +177,18 @@ tell_singles(Scope, Event, Msg) when Scope==l; Scope==g ->
Subs = gproc:select( Subs = gproc:select(
{Scope,c}, {Scope,c},
[{ {{c,Scope,{?ETag,Event}}, '$1', 1}, [], [{ {{c,Scope,{?ETag,Event}}, '$1', 1}, [],
[{{ {{c,Scope, {{?ETag,Event}} }}, '$1', {{-1,0,0}} }}] }]), [{{ {{c,Scope, {{?ETag,wrap(Event)}} }}, '$1', {{-1,0,0}} }}] }]),
_ = gproc:update_counters(Scope, Subs), _ = gproc:update_counters(Scope, Subs),
[begin P ! {?ETag, Event, Msg}, P end || {_,P,_} <- Subs]. [begin P ! {?ETag, Event, Msg}, P end || {_,P,_} <- Subs].


wrap(E) when is_tuple(E) ->
{list_to_tuple([wrap(X) || X <- tuple_to_list(E)])};
wrap(E) when is_list(E) ->
[wrap(X) || X <- E];
wrap(X) ->
X.


-spec list_singles(scope(), event()) -> [{pid(), status()}]. -spec list_singles(scope(), event()) -> [{pid(), status()}].
%% @doc Lists all single-shot subscribers of Event, together with their status %% @doc Lists all single-shot subscribers of Event, together with their status
%% @end %% @end
Expand Down

0 comments on commit ffe4140

Please sign in to comment.