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

Commit

Permalink
refactor: use promise-nodeify
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw committed Jul 26, 2019
1 parent 3a0fe8a commit 531f9ac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"once": "^1.4.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"promise-nodeify": "^3.0.1",
"promisify-es6": "^1.0.3",
"pull-defer": "~0.2.3",
"pull-stream": "^3.6.9",
Expand Down
17 changes: 0 additions & 17 deletions src/lib/callbackify.js

This file was deleted.

44 changes: 38 additions & 6 deletions src/pubsub/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
'use strict'

const callbackify = require('../lib/callbackify')
const nodeify = require('promise-nodeify')

// This file is temporary and for compatibility with legacy usage
module.exports = (send, options) => {
if (typeof send !== 'function') {
options = send
}

const ls = require('./ls')(options)
const peers = require('./peers')(options)
const publish = require('./publish')(options)
const subscribe = require('./subscribe')(options)
const unsubscribe = require('./unsubscribe')(options)

return {
ls: callbackify(require('./ls')(options)),
peers: callbackify(require('./peers')(options)),
publish: callbackify(require('./publish')(options)),
subscribe: callbackify(require('./subscribe')(options), { minArgs: 2 }),
unsubscribe: callbackify(require('./unsubscribe')(options), { minArgs: 2 })
ls: (options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(ls(options), callback)
},
peers: (topic, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(peers(topic, options), callback)
},
publish: (topic, data, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(publish(topic, data, options), callback)
},
subscribe: (topic, handler, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(subscribe(topic, handler, options), callback)
},
unsubscribe: (topic, handler, callback) => {
return nodeify(unsubscribe(topic, handler), callback)
}
}
}

0 comments on commit 531f9ac

Please sign in to comment.