2.0.0 • Published 3 months ago

run-first-only v2.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
3 months ago

NPM version Build Status Dependency Status

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