From 71f8bfdc555cf6019f7ff50acef72f756bbc15d4 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Fri, 12 Feb 2016 21:16:21 +0100 Subject: [PATCH 1/2] callback on nextTick to avoid zalgo --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e8d07291..0fc5cae7 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,9 @@ module.exports = { join(process.env.HOME || process.env.USERPROFILE, '.ipfs') } - done(null, new Node(path)) + process.nextTick(() => { + done(null, new Node(path)) + }) }, disposableApi (opts, done) { if (typeof opts === 'function') { @@ -46,7 +48,9 @@ module.exports = { const node = new Node(opts.repoPath || tempDir(), opts, true) if (typeof opts.init === 'boolean' && opts.init === false) { - done(null, node) + process.nextTick(() => { + done(null, node) + }) } else { node.init(err => { if (err) { From 9cc1c4de15e9cde4993f702dd41ca426cbdb2e1c Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Fri, 12 Feb 2016 21:17:57 +0100 Subject: [PATCH 2/2] clean up if (err) checks --- index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 0fc5cae7..e98d0c4b 100644 --- a/index.js +++ b/index.js @@ -31,10 +31,7 @@ module.exports = { } this.disposable(opts, (err, node) => { if (err) return done(err) - node.startDaemon((err, api) => { - if (err) return done(err) - done(null, api) - }) + node.startDaemon(done) }) }, disposable (opts, done) { @@ -53,10 +50,7 @@ module.exports = { }) } else { node.init(err => { - if (err) { - return done(err) - } - done(null, node) + done(err, node) }) } }