[API Reference](../README.md) > [PubSubEventService](../classes/PubSubEventService.md)



# Class: PubSubEventService


A Pub/Sub event system that enables you to subscribe to various events published by Arc.js. For more information, see [Pub/Sub Events](Events#pubsubevents).

## Hierarchy

**PubSubEventService**

↳  [TransactionService](TransactionService.md)








## Index

### Methods

* [clearAllSubscriptions](PubSubEventService.md#clearAllSubscriptions)
* [isTopicSpecifiedBy](PubSubEventService.md#isTopicSpecifiedBy)
* [publish](PubSubEventService.md#publish)
* [subscribe](PubSubEventService.md#subscribe)
* [unsubscribe](PubSubEventService.md#unsubscribe)



---
## Methods
<a id="clearAllSubscriptions"></a>

### «Static» clearAllSubscriptions

► **clearAllSubscriptions**(): `void`



*Defined in [pubSubEventService.ts:38](https://github.com/daostack/arc.js/blob/f343aa24/lib/pubSubEventService.ts#L38)*



Remove all subscriptions




**Returns:** `void`





___

<a id="isTopicSpecifiedBy"></a>

### «Static» isTopicSpecifiedBy

► **isTopicSpecifiedBy**(matchTemplates: *`Array`.<`string`>⎮`string`*, topic: *`string`*): `boolean`



*Defined in [pubSubEventService.ts:91](https://github.com/daostack/arc.js/blob/f343aa24/lib/pubSubEventService.ts#L91)*



Return whether topic is specified by matchTemplates.

Examples:

matchTemplates: ["foo"] topic: "foo.bar" result: true

matchTemplates: ["foo.bar"] topic: "foo" result: false

Or a wildcard:

matchTemplates: "*" topic: "foo" result: true


**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| matchTemplates | `Array`.<`string`>⎮`string`   |  - |
| topic | `string`   |  - |





**Returns:** `boolean`





___

<a id="publish"></a>

### «Static» publish

► **publish**(topic: *`string`*, payload: *`any`*): `boolean`



*Defined in [pubSubEventService.ts:18](https://github.com/daostack/arc.js/blob/f343aa24/lib/pubSubEventService.ts#L18)*



Send the given payload to subscribers of the given topic.


**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| topic | `string`   |  See [subscribe](PubSubEventService#subscribe) |
| payload | `any`   |  Sent in the subscription callback. |





**Returns:** `boolean`
True if there are any subscribers






___

<a id="subscribe"></a>

### «Static» subscribe

► **subscribe**(topics: *`string`⎮`Array`.<`string`>*, callback: *[EventSubscriptionCallback](../#EventSubscriptionCallback)*): [IEventSubscription](../interfaces/IEventSubscription.md)



*Defined in [pubSubEventService.ts:29](https://github.com/daostack/arc.js/blob/f343aa24/lib/pubSubEventService.ts#L29)*



Subscribe to the given topic or array of topics.


**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| topics | `string`⎮`Array`.<`string`>   |  Identifies the event(s) to which you wish to subscribe |
| callback | [EventSubscriptionCallback](../#EventSubscriptionCallback)   |  The function to call when the requested events are published |





**Returns:** [IEventSubscription](../interfaces/IEventSubscription.md)
An interface with `.unsubscribe()`.  Be sure to call it!






___

<a id="unsubscribe"></a>

### «Static» unsubscribe

► **unsubscribe**(key: *[EventSubscriptionKey](../#EventSubscriptionKey)*, milliseconds?: *`number`*): `Promise`.<`void`>



*Defined in [pubSubEventService.ts:52](https://github.com/daostack/arc.js/blob/f343aa24/lib/pubSubEventService.ts#L52)*



Unsubscribes after optional timeout. When passed a token, removes a specific subscription, when passed a callback, removes all subscriptions for that callback, when passed a topic, removes all subscriptions for the topic hierarchy.


**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| key | [EventSubscriptionKey](../#EventSubscriptionKey)  | - |   A token, function or topic to unsubscribe. |
| milliseconds | `number`  |  -1 |   number of milliseconds to timeout.Default is -1 which means not to timeout at all. |





**Returns:** `Promise`.<`void`>





___


