Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 674e257

Browse files
committed
all pubsub tests passing
1 parent e498181 commit 674e257

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"form-data": "^2.3.1",
7777
"gulp": "^3.9.1",
7878
"hat": "0.0.3",
79-
"interface-ipfs-core": "~0.36.6",
79+
"interface-ipfs-core": "~0.36.7",
8080
"ipfsd-ctl": "~0.24.1",
8181
"left-pad": "^1.2.0",
8282
"lodash": "^4.17.4",
@@ -121,7 +121,7 @@
121121
"joi": "^13.0.2",
122122
"libp2p": "~0.13.1",
123123
"libp2p-circuit": "~0.1.4",
124-
"libp2p-floodsub": "~0.11.1",
124+
"libp2p-floodsub": "~0.12.1",
125125
"libp2p-kad-dht": "~0.6.0",
126126
"libp2p-mdns": "~0.9.1",
127127
"libp2p-multiplex": "~0.5.0",

src/core/components/pubsub.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,34 @@ module.exports = function pubsub (self) {
1818
options = {}
1919
}
2020

21+
function subscribe (cb) {
22+
if (self._pubsub.listenerCount(topic) === 0) {
23+
self._pubsub.subscribe(topic)
24+
}
25+
26+
self._pubsub.on(topic, handler)
27+
setImmediate(() => callback())
28+
}
29+
2130
if (!callback) {
2231
return new Promise((resolve, reject) => {
23-
subscribe(topic, options, handler, (err) => {
32+
subscribe((err) => {
2433
if (err) {
2534
return reject(err)
2635
}
2736
resolve()
2837
})
2938
})
39+
} else {
40+
subscribe(callback)
3041
}
31-
32-
subscribe(topic, options, handler, callback)
3342
},
3443

3544
unsubscribe: (topic, handler) => {
36-
const ps = self._pubsub
37-
38-
ps.removeListener(topic, handler)
45+
self._pubsub.removeListener(topic, handler)
3946

40-
if (ps.listenerCount(topic) === 0) {
41-
ps.unsubscribe(topic)
47+
if (self._pubsub.listenerCount(topic) === 0) {
48+
self._pubsub.unsubscribe(topic)
4249
}
4350
},
4451

@@ -60,9 +67,7 @@ module.exports = function pubsub (self) {
6067
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
6168
}
6269

63-
const subscriptions = Array.from(
64-
self._pubsub.subscriptions
65-
)
70+
const subscriptions = Array.from(self._pubsub.subscriptions)
6671

6772
setImmediate(() => callback(null, subscriptions))
6873
}),
@@ -83,15 +88,4 @@ module.exports = function pubsub (self) {
8388
return self._pubsub.setMaxListeners(n)
8489
}
8590
}
86-
87-
function subscribe (topic, options, handler, callback) {
88-
const ps = self._pubsub
89-
90-
if (ps.listenerCount(topic) === 0) {
91-
ps.subscribe(topic)
92-
}
93-
94-
ps.on(topic, handler)
95-
setImmediate(() => callback())
96-
}
9791
}

0 commit comments

Comments
 (0)