node-singleflight
Version:
provides a duplicate function call suppression
40 lines (27 loc) • 751 B
Markdown
provides a duplicate function call suppression
If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.
argument `func` may need to set up `timeout` in some ways, otherwise it may create too many listeners and cause memory leak
Yarn
```
yarn add node-singleflight
```
NPM
```
npm install node-singleflight --save
```
+ See [do.test.js](./lib/do.test.js) File
```js
const singleflight = require('node-singleflight')
async function example() {
let data = singleflight.Do('SomeKey', async () => {
let data = await doSomething()
let processed = processData(data)
return processed
})
return data
}
```