This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ const promisify = require('promisify-es6')
4
4
5
5
module . exports = function pubsub ( self ) {
6
6
return {
7
- subscribe : ( topic , options , handler , callback ) => {
7
+ subscribe : ( topic , handler , options , callback ) => {
8
8
if ( typeof options === 'function' ) {
9
- callback = handler
10
- handler = options
9
+ callback = options
11
10
options = { }
12
11
}
13
12
@@ -20,13 +19,19 @@ module.exports = function pubsub (self) {
20
19
resolve ( )
21
20
} )
22
21
} )
23
- } else {
24
- self . _libp2pNode . pubsub . subscribe ( topic , options , handler , callback )
25
22
}
23
+
24
+ self . _libp2pNode . pubsub . subscribe ( topic , options , handler , callback )
26
25
} ,
27
26
28
- unsubscribe : ( topic , handler ) => {
27
+ unsubscribe : ( topic , handler , callback ) => {
29
28
self . _libp2pNode . pubsub . unsubscribe ( topic , handler )
29
+
30
+ if ( ! callback ) {
31
+ return Promise . resolve ( )
32
+ }
33
+
34
+ process . nextTick ( ( ) => callback ( ) )
30
35
} ,
31
36
32
37
publish : promisify ( ( topic , data , callback ) => {
Original file line number Diff line number Diff line change @@ -33,16 +33,13 @@ exports.subscribe = {
33
33
res . write ( '{}\n' )
34
34
35
35
const unsubscribe = ( ) => {
36
- ipfs . pubsub . unsubscribe ( topic , handler )
37
- res . end ( )
36
+ ipfs . pubsub . unsubscribe ( topic , handler , ( ) => res . end ( ) )
38
37
}
39
38
40
39
request . once ( 'disconnect' , unsubscribe )
41
40
request . once ( 'finish' , unsubscribe )
42
41
43
- ipfs . pubsub . subscribe ( topic , {
44
- discover : discover
45
- } , handler , ( err ) => {
42
+ ipfs . pubsub . subscribe ( topic , handler , { discover : discover } , ( err ) => {
46
43
if ( err ) {
47
44
return reply ( err )
48
45
}
You can’t perform that action at this time.
0 commit comments