Skip to content

postal.getSubscribersFor

ifandelse edited this page May 10, 2014 · 1 revision

postal.getSubscribersFor

This method can be called 3 different ways:


postal.getSubscribersFor()

returns: an array of all the current SubscriptionDefinition objects which are subscribed to any topic on any channel.

Example Usage:

var results = postal.getSubscribersFor();

### postal.getSubscribersFor( options )

options - an object that can contain one or more of the following properties:

  • channel - (optional) the channel name
  • topic - (optional) a topic that will be compared to the SubscriptionDefinition topic binding using the resolver.
  • context - (optional) an instance used in a withContext call which lets you retrieve any SubscriptionDefinition instances that are using a specific context for their callbacks.

In addition to the above properties on the options argument, you can provide any other properties which you might have added to the SubscriptionDefinition instance. For example, if you've added a foo property to the subscription with a value of "bar", you can call postal.getSubscribersFor({ foo: "bar" });.

returns: an array of SubscriptionDefinition objects that match the query options.

Example Usage:

var results = postal.getSubscribersFor({
  channel:"orders",
  topic: "customer.addItem"
});
// OHSNAP!  Making subscribers mad since 2011...
_.each( results, function(sub) {
  sub.withDelay(4000);
});

### postal.getSubscribersFor( predicate )

predicate - a function that takes a SubscriptionDefinition as an argument and returns true if the SubscriptionDefinition should be included in the results, or false if not.

returns: an array of SubscriptionDefinition objects.

Example Usage:

// passing a predicate
var results = postal.getSubscribersFor(function (sub) {
    return sub.foo === "bar";
});
// OHSNAP!  Making subscribers mad since 2011...
_.each(results, function (sub) {
    sub.withDelay(4000);
});