Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 2d437a1

Browse files
committed
Merge remote-tracking branch 'origin'
2 parents 2e3fbb2 + 78d3816 commit 2d437a1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

SPEC/PUBSUB.md

+41
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [pubsub.subscribe](#pubsubsubscribe)
44
* [pubsub.unsubscribe](#pubsubunsubscribe)
5+
* [pubsub.unsubscribeAll](#pubsubunsubscribeall)
56
* [pubsub.publish](#pubsubpublish)
67
* [pubsub.ls](#pubsubls)
78
* [pubsub.peers](#pubsubpeers)
@@ -78,6 +79,46 @@ ipfs.pubsub.subscribe(topic, receiveMsg, (err) => {
7879
})
7980
```
8081

82+
#### `pubsub.unsubscribeAll`
83+
84+
> Unsubscribes from a pubsub topic.
85+
86+
##### Go **WIP**
87+
88+
##### JavaScript - `ipfs.pubsub.unsubscribe(topic, handler, [callback])`
89+
90+
- `topic: String` - The topic to unsubscribe from
91+
- `callback: (Error) => {}` (Optional) Called once the unsubscribe is done.
92+
93+
If no `callback` is passed, a [promise][] is returned.
94+
95+
This works like `EventEmitter.removeAllListeners`, The underlying subscription will only be canceled once all listeners for a topic have been removed.
96+
97+
**Example:**
98+
99+
```JavaScript
100+
const topic = 'fruit-of-the-day'
101+
102+
ipfs.pubsub.subscribe(topic, (msg) => console.log(msg.toString()), (err) => {
103+
if (err) {
104+
return console.error(`failed to subscribe to ${topic}`, err)
105+
}
106+
107+
console.log(`subscribed to ${topic}`)
108+
109+
// unsubscribe a second later
110+
setTimeout(() => {
111+
ipfs.pubsub.unsubscribeAll(topic,(err) => {
112+
if (err) {
113+
return console.error(`failed to unsubscribe from ${topic}`, err)
114+
}
115+
116+
console.log(`unsubscribed from ${topic}`)
117+
})
118+
}, 1000)
119+
})
120+
```
121+
81122
A great source of [examples][] can be found in the tests for this API.
82123

83124
#### `pubsub.publish`

0 commit comments

Comments
 (0)