New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

promizee

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promizee

Memoize(e) a function which returns a promise, which clears its cache once the promise has resolved

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

So you've memoize(e)d a function which returns a promise, and you'd like the result cache to expire once the promise has been resolved/rejected?

This module can be swapped-in for the standard memoizee() just for this purpose.

Usage:

promizee(promiserFunc, [options])
  • promiserFunc - a function which returns a Promise.
  • options - optional options object passed straight to memoizee() (documentation)

Returns a memoized function which clears its cache after the Promise it returns is resolved/rejected.

Example:

var promizee = require('promizee');
var Promise = require('bluebird');

function doubleIt(it) {
 	// do something that takes some time
	return Promise.delay(5000).then(function(){
		return it + it;
	});
}

var promizeedDoubleIt = promizee(doubleIt);

promizeedDoubleIt(5); // returns new Promise that resolves to 10
promizeedDoubleIt(5); // Cache hit - returns the same Promise as above
promizeedDoubleIt(6); // returns a new Promise that resolves to 12

setTimeout(function(){
	// after 6 seconds
	promizeedDoubleIt(5); // returns a new Promise that resolves to 10
	promizeedDoubleIt.clear() // manually clear the cache
	promizeedDoubleIt(5); // returns a new Promise that resolves to 10
}, 6000);

FAQs

Package last updated on 03 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts