anchor.diff:              Pid ! Event,
               ignored
       end.
  -
  -
  -subscribe_node(Node, #subscribe_all_state{name=Name, func=Fun,
  -                                          func_state=FState}) ->
  -    subscribe({Name, Node}, Fun, FState).
  
positive.code: init(State) ->
      {ok, State}.
  
  %% Only set initial nodes if we haven't yet received an event
  handle_call({init_nodes, Nodes}, State = #subscribe_all_state{noderefs=[]}) ->
      NodeRefs = [{Node, subscribe_node(Node, State)} || Node <- Nodes],
      {ok, ok, State#subscribe_all_state{noderefs=NodeRefs}};
  handle_call({init_nodes, _}, State = #subscribe_all_state{noderefs=[_|_]}) ->
      {ok, ok, State}.
  
  
  handle_event(Event, State = #state{func=Fun, func_state=FS}) ->
      NewState = Fun(Event, FS),
      {ok, State#state{func_state=NewState}};
  handle_event({ns_node_disco_events, _OldNodes, Nodes},
               State = #subscribe_all_state{noderefs=NodeRefs}) ->
      NewNodeRefs = [{N, subscribe_node(N, State)} ||
                        N <- Nodes, not lists:keymember(N, 1, NodeRefs)],
      KeepNodeRefs = [NR || NR = {N, _} <- NodeRefs, not lists:member(N, Nodes)],
      {ok, State#subscribe_all_state{noderefs=NewNodeRefs ++ KeepNodeRefs}}.
  
  
  handle_info(_Msg, State) ->
      {ok, State}.
  
  
  terminate(_Reason, #subscribe_all_state{noderefs=NodeRefs, name=Name}) ->
      lists:foreach(fun ({Node, Ref}) ->
                            unsubscribe({Name, Node}, Ref)
                    end, NodeRefs);
  terminate(_Reason, _State) ->
      ok.
  
  
negative.code:                                    #state{func=Fun, func_state=State}),
      Ref.
  
  unsubscribe(Name, Ref) ->
      gen_event:delete_handler(Name, {?MODULE, Ref}, unsubscribed).
  
  %%
  %% gen_event callbacks
  