https://github.com/pirxpilot/run-first-only
Execute only first call of the async function.
https://github.com/pirxpilot/run-first-only
Last synced: about 1 month ago
JSON representation
Execute only first call of the async function.
- Host: GitHub
- URL: https://github.com/pirxpilot/run-first-only
- Owner: pirxpilot
- Created: 2017-04-28T00:54:39.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-02-13T20:49:38.000Z (over 2 years ago)
- Last Synced: 2025-10-15T09:23:55.074Z (9 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# 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
```sh
$ npm install --save run-first-only
```
## Usage
```js
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](https://furkot.com)
[async.memoize]: http://caolan.github.io/async/docs.html#memoize
[npm-image]: https://img.shields.io/npm/v/run-first-only
[npm-url]: https://npmjs.org/package/run-first-only
[build-url]: https://github.com/pirxpilot/run-first-only/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/run-first-only/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/run-first-only
[deps-url]: https://libraries.io/npm/run-first-only