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

provisor

v1.0.111

Published

Provisor is a simple promise super visor with cancelable functionality

Downloads

3

Readme

provisor

provisor is simple JavaScript module that watch promises in specific namespace, with cancelable.

Example

See the example.js to details.

var provisor = require('provisor');

function doAsync() {
	return new Promise((resolve, reject) => {
		setTimeout(resolve, 3000);
	});
}

var request1 = doAsync();
var request2 = doAsync();

provisor.addNamespace('example');

// Make sure to use that returning object from provisor.save()
request1 = provisor.save('example', 'async1', request1);
request2 = provisor.save('example', 'async2', request2);
// request2 = provisor.save('example', 'async2', request2, { timeout: 1000 });

request1
.then(() => console.log('Done!'))
.catch((err) => console.log('Error', err));

request2
.then(() => console.log('Done!'))
.catch((err) => console.log('Error', err));

// Cancel example::async2
provisor.cancel('example', 'async2');		// comment this line when you want to test timeout

Usage

$ npm install --save provisor
var provisor = require('provisor');

...

// PROFIT!!!

Important

This module not actually cancel the promise because it's not possible. So when you do some async job, and it ends after you cancel the promise, previous async job is still completed, but not it will not resolve the promise, because it's already did.

If you run the example, I canceled all promises, so the promise flow immediately ends, but timer is still going on, and process ends when timer is done.

Most of situations, it should be fine, especially in Web Development, but some cases, it could be a problem. So make sure that your situation is suitable for using this or not.

API

Object provisor

Returns provisor.

Object provisor.namespace

Returns all namespace. Namespace is just simple object.

void provisor.addNamespace(String namespace)

Add new namespace.

void provisor.removeNamespace(String namespace)

Remove specified namespace. It will throw exception if namespace wasn't exists.

Boolean provisor.hasNamespace(String namespace)

Returns true if specified namespace exists.

Promise provisor.save(String namespace, String key, Promise promise, Object options)

Save passed promise into specified namespace::key. You can access saved promise as "provisor.namespace.key". It returns new promise object that continue promise.

This method will remove promise from namespace::key automatically when it's done.

void provisor.cancel(String namespace, String key)

Forcely cancel specified namespace::key promise. Note that if you are using Fetch, using this just change the promise flow, not actually cancel XHR, it's limitation of Fetch API.

void provisor.cancelAll(String namespace)

Forcely cancel all promises in specified namespace.

Object provisor.use(String namespace)

Returns new object that has same functions as provisor, but every namespace argument is binded automatically.

provisor.addNamespace('space1');
var iProvisor = provisor.use('space1');

var request = doAsync();

iProvisor.save('key1', request);	// You can now skip namespace!
iProvisor.cancel('key1');

License

MIT. Free to use.