Documentation is generated by [JSDoc](https://github.com/jsdoc3/jsdoc) and [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). *** ## Functions
throwException(ex)

Returns a function that throws the passed exception, for use as argument for setTimeout

publish(message, data) ⇒ Boolean

Publishes the message, passing the data to it's subscribers

publishSync(message, data) ⇒ Boolean

Publishes the message synchronously, passing the data to it's subscribers

subscribe(message, func) ⇒ String

Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe

subscribeOnce(message, func) ⇒ PubSub

Subscribes the passed function to the passed message once

clearAllSubscriptions()

Clears all subscriptions

clearAllSubscriptions() ⇒ int

Clear subscriptions by the topic

countSubscriptions() ⇒ Array

Count subscriptions by the topic

getSubscriptions()

Gets subscriptions by the topic

subscribeOnce(value)

Removes subscriptions

## throwException(ex) Returns a function that throws the passed exception, for use as argument for setTimeout **Kind**: global function | Param | Type | Description | | --- | --- | --- | | ex | Object | An Error object | ## publish(message, data) ⇒ Boolean Publishes the message, passing the data to it's subscribers **Kind**: global function | Param | Type | Description | | --- | --- | --- | | message | String | The message to publish | | data | | The data to pass to subscribers | ## publishSync(message, data) ⇒ Boolean Publishes the message synchronously, passing the data to it's subscribers **Kind**: global function | Param | Type | Description | | --- | --- | --- | | message | String | The message to publish | | data | | The data to pass to subscribers | ## subscribe(message, func) ⇒ String Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe **Kind**: global function | Param | Type | Description | | --- | --- | --- | | message | String | The message to subscribe to | | func | function | The function to call when a new message is published | ## subscribeOnce(message, func) ⇒ PubSub Subscribes the passed function to the passed message once **Kind**: global function | Param | Type | Description | | --- | --- | --- | | message | String | The message to subscribe to | | func | function | The function to call when a new message is published | ## clearAllSubscriptions() Clears all subscriptions **Kind**: global function **Access**: public ## clearAllSubscriptions() ⇒ int Clear subscriptions by the topic **Kind**: global function **Access**: public ## countSubscriptions() ⇒ Array Count subscriptions by the topic **Kind**: global function **Access**: public ## getSubscriptions() Gets subscriptions by the topic **Kind**: global function **Access**: public ## subscribeOnce(value) Removes subscriptions - When passed a token, removes a specific subscription. - When passed a function, removes all subscriptions for that function - When passed a topic, removes all subscriptions for that topic (hierarchy) **Kind**: global function **Access**: public | Param | Type | Description | | --- | --- | --- | | value | String \| function | A token, function or topic to unsubscribe from | **Example** ```js // Unsubscribing with a token var token = PubSub.subscribe('mytopic', myFunc); PubSub.unsubscribe(token); ``` **Example** ```js // Unsubscribing with a function PubSub.unsubscribe(myFunc); ``` **Example** ```js // Unsubscribing from a topic PubSub.unsubscribe('mytopic'); ``` * * * © 2018 [Morgan Roderick](https://roderick.dk), [http://roderick.dk/](https://roderick.dk) <[morgan@roderick.dk](mailto:morgan@roderick.dk)>