run-first-only
v2.0.0
Published
Execute only first call of the async function.
Downloads
2
Maintainers
Readme
run-first-only
Execute only first call of the async function. Like async.memoize, but limited to no-args functions, and without any dependencies. Use it in the browser.
After first call, all subsequent once will get the same result. If first call is still in progress, subsequent calls are placed in the queue and notified when initial operation is completed.
Install
$ npm install --save run-first-only
Usage
var runFirstOnly = require('run-first-only');
function openDatabase(fn) {
// do something async to open DB
asyncOperationThatOpensDatabase(connection, name, options, fn)
}
var open = runFirstOnly(openDatabase);
open(function(err, database) {
// database is open here
});
open(function(err, database) {
// it's still open here and it was opened only once
});
License
MIT © Damian Krzeminski