From a1b3632543a05c9897f664fc32ed07358a5c9816 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Tue, 12 Feb 2019 16:33:10 -0800 Subject: [PATCH 1/2] Feature: Ready Promise --- src/core/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/index.js b/src/core/index.js index ba43f5703e..17fdc25cae 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -187,6 +187,14 @@ class IPFS extends EventEmitter { } boot(this) + this.once('ready', () => this.__ready = true) + } + get ready () { + return new Promise((resolve, reject) => { + if (this.__ready) return resolve(this) + this.on('ready', () => resolve(this)) + this.on('error', reject) + }) } } @@ -195,3 +203,8 @@ exports = module.exports = IPFS exports.createNode = (options) => { return new IPFS(options) } + +exports.create = (options) => { + let node = new IPFS(options) + return node.ready +} From 5fb624f90e739eafc12bb2f43715439945794708 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Thu, 14 Feb 2019 16:42:18 -0800 Subject: [PATCH 2/2] Fixed Assignment Linter Error --- src/core/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/index.js b/src/core/index.js index 17fdc25cae..4bcd07a4b3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -187,7 +187,7 @@ class IPFS extends EventEmitter { } boot(this) - this.once('ready', () => this.__ready = true) + this.once('ready', () => { this.__ready = true }) } get ready () { return new Promise((resolve, reject) => {