Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

emersion/node-async-once-save

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-async-once-save

Execute an async function once and save the result.

The async function can be any function, unlike async-once.

Usage

var once = require('async-once-save');

var i = 0;
var asyncFunction = once(function (j, done) {
	setTimeout(function () {
		i++;
		done(i, j);
	}, 1000);
});

asyncFunction(42, function (i, j) {
	console.log(i, j); // 1, 42

	// The function as been executed once and its result has been saved.
	// Another call won't wait for 1 second and will return the same result.

	asyncFunction(76, function (i, j) {
		console.log(i, j); // 1, 42
	});
});

License

MIT

About

Execute an async function once and save the result

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published