DEFERRALS
Deferrals is a very simple library that enables the creation of any number of promises which can then be awaited in any other code in your app.
Installation
npm i deferrals
yarn add deferrals
Usage Example
const {
makeDefer,
waitForDefer,
resolveDefer
} = require("deferrals");
const await1 = async() => {
const value = await waitForDefer("Defer1");
console.log(value);
}
const await2 = async() => {
const value = await waitForDefer("Defer2");
console.log(value);
}
makeDefer('Defer1');
makeDefer('Defer2');
await1();
await2();
setTimeout(() => {
resolveDefer("Defer1", "Defer 1 Resolved!");
}, 1000);
setTimeout(() => {
resolveDefer("Defer2", "Defer 2 Resolved!");
}, 2000);
These deferrals don't need to be created and used in the same file or folder - you can import the library and get the deferals from any file in your project!
Documentation
Did this thing in about 5 minutes, give me a few more to create some potent docs :P