async-once-save

0.1.0 • Public • Published

node-async-once-save

Execute an async function once and save the result

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

Licence

MIT

Package Sidebar

Install

npm i async-once-save

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • emersion