Execute only first call of the async function.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.editorconfig
.gitignore
.jshintrc
.travis.yml
History.md
Makefile
Readme.md
index.js
package.json
yarn.lock

Readme.md

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