run-first-only

2.0.0 • Public • Published

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

Package Sidebar

Install

npm i run-first-only

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

2.47 kB

Total Files

3

Last publish

Collaborators

  • pirxpilot