From 6e167f2f0f71f1967c7068606a8cab81183a70cb Mon Sep 17 00:00:00 2001 From: mixmix Date: Wed, 13 Dec 2023 14:45:03 +1300 Subject: [PATCH] provide callback for muxrpc.close --- index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1c35dbd..f3891c8 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,8 @@ const path = require('path') const createClient = require('ssb-client/client') +const ALREADY_FOLLOWING = 'already following' + // invite plugin // adds methods for producing invite-codes, // which peers can use to command your server to follow them. @@ -27,6 +29,14 @@ function isNumber (n) { return typeof n === 'number' && !isNaN(n) } +function logErrorCb (err) { + if (err) console.log(err) +} + +function contNoop (cb) { + cb() +} + module.exports = { name: 'invite', version: '1.0.0', @@ -244,15 +254,15 @@ module.exports = { // command the peer to follow me rpc.invite.use({ feed: server.id }, (err, msg) => { - if (err && err.message !== 'already following') { + if (err && err.message !== ALREADY_FOLLOWING) { return cb(explain(err, 'invite not accepted')) } // (maybe) follow and announce the pub cont.para([ ( - (err && err.message === 'already following') - ? (cb) => cb() + (err && err.message === ALREADY_FOLLOWING) + ? contNoop : cont(server.publish)({ type: 'contact', following: true, @@ -266,12 +276,12 @@ module.exports = { type: 'pub', address: opts }) - : (cb) => cb() + : contNoop ) ])((err, results) => { if (err) return cb(err) - rpc.close() - rpc.close() + rpc.close(logErrorCb) + rpc.close(logErrorCb) // ignore err if this is new style invite if (server.gossip && server.gossip.add) server.gossip.add(ref.parseInvite(invite).remote, 'seed') cb(null, results)