Function execution task scheduler.
A utility to help you solve a sequence of task-functions.
$ npm install ultra-promise
const UltraPromise = require("ultra-promise").default;
UltraPromise((resolve, reject) => {
setTimeout(() => resolve(123), 1000);
}).then((result, resolve) => {
setTimeout(() => resolve(result + 333, 789), 1000);
}).finish((firstFinalResult, secondFinalResult) => {
console.log(123, firstFinalResult, secondFinalResult); //123 456 789
});
Types: HERE!
(new?) UltraPromise(configs?: UltraPromiseConfigs | PromiseFn, fn?: PromiseFn) => UltraPromiseInstance
The main function that launches the scheduler. Called with the new operator only if the original UltraPromise is exported (default exports the wrapper).
Sets the settings for UltraPromise.
Allows you to set subsequent functions.
Sets a one-time error handler that is called when reject is called. A repeated call will replace the existing handler. It can only take one error argument, unlike subsequent methods.
Sets up a one-time handler that is called in any case, whether there was an error or not.
Installs final handlers. Can be called multiple times, each handler will be called in turn. Can also act as a multiple error handler if the first argument is called "$error".
Forcibly starts the process of performing the assigned tasks.
The task function that is passed to then and the beginning. resolve lets you move on to the next task, reject jumps directly to the error handler. It is also possible to jump directly to the final handlers using this.toFinish .
const { UltraPromise } = require("ultra-promise");
new UltraPromise({ runMustCalled: true }, resolve => {
resolve(true, true, true);
}).finish((t1, t2, t3) => {
console.log(t1, t2, t3); //true true true
}).run();
const { UltraPromise } = require("ultra-promise");
new UltraPromise(resolve => {
resolve(true, true, true);
}).then(function(t1, t2, t3, resolve) {
this.toFinish(t1, t2, t3);
resolve(t1, t2, t3, true, true);
}).then((t1, t2, t3, t4, t5, resolve) => {
resolve(t1, t2, t3, t4, t5, true);
}).finish((...args) => {
console.log(args.length); //3
});
const { UltraPromiseW } = require("ultra-promise");
async function test() {
const result = await UltraPromiseW(resolve => {
setTimeout(() => resolve(1), 100);
}).then((one, resolve) => {
setTimeout(() => resolve(one, 2), 100);
}).then((one, two, resolve) => {
setTimeout(() => resolve(one, two, 3), 100);
});
console.log(...result); //1 2 3
}
test();
Yandex Mail - vladimirvsevolodovi@yandex.ru
Github - https://github.com/StormExecute/
Github - https://github.com/StormExecute/ultra-promise/
NPM - https://www.npmjs.com/package/ultra-promise/
MIT - https://mit-license.org/