run-first-only

Execute only first call of the async function.


Keywords
run-first-only, async, once, memoize
License
MIT
Install
npm install run-first-only@1.0.0

Documentation

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