1.0.4 • Published 5 years ago
global-promise v1.0.4
Global Promise
A helper library to create a promise to be resolved/rejected from your other parts of codebase globally.
Installation
Install it from npm:
$ npm install global-promiseor
$ yarn add global-promiseMotivation
Sometimes, we create a promise and we needed to resolve/reject it from other part of codebase globally.
We can achieve the same by implementing event driven code using EventTarget or EventEmitter ,
but it will require a lot of code.
Solve it with GPromise with a few of lines of code:
import * as GPromise from 'global-promise';
// Creates a promise to be settled from other parts of code.
GPromise.create('my_id')
.then((val) => {
console.log( `Promise with 'my_id' id is resolved with: ${val}` );
});
// In your other part of code:
setTimeout(() => {
// Resolve the promise we have just created with id 'my_id' above from other part of your codebase.
GPromise.resolve('my_id', 'my_value');
}, 2000);Test
Run:
yarn testContributing
Your PRs and stars are always welcome.