From 0c12234bb1af458bc919ad12ecef06542a04462f Mon Sep 17 00:00:00 2001 From: Simon Stone Date: Tue, 6 Nov 2018 13:15:05 +0000 Subject: [PATCH] [FABN-1000] Use less strict "is promise" check In complex Node.js applications, two or more promise implementations may be available, providing different Promise classes. These different Promise classes have the same standard interface, but you cannot rely on instanceof to work as you would expect. This has been seen as a problem in the ctor for AbstractEventStrategy when running within VSCode, where an error is thrown because a promise is not an instanceof Promise (even though it is a valid promise!). Use the "is-promise" module instead which checks to see if the object is "thenable" (has a .then()) method instead. Change-Id: I6f47877b9be5815379163ffe5dc8d8cae1deba7b Signed-off-by: Simon Stone --- fabric-network/lib/impl/event/abstracteventstrategy.js | 3 ++- fabric-network/package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fabric-network/lib/impl/event/abstracteventstrategy.js b/fabric-network/lib/impl/event/abstracteventstrategy.js index e4d2dc703f..0e6099c931 100644 --- a/fabric-network/lib/impl/event/abstracteventstrategy.js +++ b/fabric-network/lib/impl/event/abstracteventstrategy.js @@ -6,6 +6,7 @@ 'use strict'; +const isPromise = require('is-promise'); const logger = require('fabric-network/lib/logger').getLogger('AbstractStrategy'); /** @@ -24,7 +25,7 @@ class AbstractEventStrategy { * @param {Promise.ChannelEventHub[]} eventHubsPromise Promise to event hubs for which to process events. */ constructor(eventHubsPromise) { - if (!(eventHubsPromise instanceof Promise)) { + if (!isPromise(eventHubsPromise)) { const message = 'Expected event hubs to be a Promise but was ' + typeof eventHubsPromise; logger.error('constructor:', message); throw new Error(message); diff --git a/fabric-network/package.json b/fabric-network/package.json index 7a0a9b00d1..5e3fe1d728 100644 --- a/fabric-network/package.json +++ b/fabric-network/package.json @@ -22,6 +22,7 @@ }, "types": "./types/index.d.ts", "dependencies": { + "is-promise": "^2.1.0", "nano": "^6.4.4", "rimraf": "^2.6.2", "uuid": "^3.2.1"