npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ultra-promise

v1.0.0

Published

Function execution task scheduler

Downloads

7

Readme

ultra-promise NPM version

Function execution task scheduler.

Description

A utility to help you solve a sequence of task-functions.

Table of Contents

Install

$ npm install ultra-promise

Usage


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

});

API

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).

UltraPromiseInstance.config(configs: UltraPromiseConfigs) => UltraPromiseInstance

Sets the settings for UltraPromise.

UltraPromiseInstance.then(fn: PromiseFn) => UltraPromiseInstance

Allows you to set subsequent functions.

UltraPromiseInstance.catch(fn: (error: any) => void) => UltraPromiseInstance

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.

UltraPromiseInstance.finally(fn: (error: any, ...args: any[]) => void) => UltraPromiseInstance

Sets up a one-time handler that is called in any case, whether there was an error or not.

UltraPromiseInstance.finish(fn: Function) => UltraPromiseInstance

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".

UltraPromiseInstance.run() => true

Forcibly starts the process of performing the assigned tasks.

PromiseFn(this: { toFinish(...args: any[]): true }, resolve: Function, reject: Function) => any

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 .

Examples

Instant start with configs


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();

Instant finish


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

});

Example with await


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();

Contacts

Yandex Mail - [email protected]

Github - https://github.com/StormExecute/

Platforms

Github - https://github.com/StormExecute/ultra-promise/

NPM - https://www.npmjs.com/package/ultra-promise/

License

MIT - https://mit-license.org/