Promise toolkit
yarn add @aegenet/belt-promise@^1.4.0
# or
npm i @aegenet/belt-promise@^1.4.0
import { isPromise } from '@aegenet/belt-promise';
isPromise(Promise.resolve(true)); // true
isPromise(5); // false
isPromise(null); // false
isPromise(undefined); // false
isPromise(() => true); // false
isPromise({ id: 5 }); // false
import { delay } from '@aegenet/belt-promise';
await delay(500); // ms
import { runSequentially } from '@aegenet/belt-promise';
await runSequentially(
() => {
/** Step 1 */;
},
() => {
/** Step 2 */;
}
);
import { collectSequentially } from '@aegenet/belt-promise';
const results = await collectSequentially(
() => {
/** Step 1 */;
return 5;
},
() => {
/** Step 2 */;
return 3;
}
);
// results: [5, 3]