![License](https://img.shields.io/github/license/rousan/gpromise.svg)
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-promise
or
$ yarn add global-promise
Motivation
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 GPromise from 'global-promise';
GPromise.create('my_id')
.then((val) => {
console.log( `Promise with 'my_id' id is resolved with: ${val}` );
});
setTimeout(() => {
GPromise.resolve('my_id', 'my_value');
}, 2000);
Test
Run:
yarn test
Contributing
Your PRs and stars are always welcome.