Skip to content

Commit

Permalink
Added how to import the module
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Apr 27, 2020
1 parent 11408ca commit 06d0eba
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,9 @@ The goal of this module is to hold on the very first promise that asks for a spe
In the following example, after the first `samePromise()`, all other `samePromise()` invokes will simply hold until the first invoke has been resolved, granting that for 300 ms, dictated in the following example by `setTimeout`, no extra timer will be set, and `++samePromiseCalls` won't be incremented more than once.

```js
import idPromise from 'id-promise';
// const idPromise = require('id-promise');

let samePromiseCalls = 0;
const samePromise = () => idPromise(
'some-unique-id:samePromise',
Expand All @@ -31,6 +34,9 @@ If the callback is executed within a _forked_ worker, it will put on hold the sa
This is specially useful when a single _fork_ would need to perform a potentially very expensive operation, either DB or file system related, but it shouldn't perform such operation more than once, as both DB and file system are shared across all workers.

```js
import idPromise from 'id-promise';
// const idPromise = require('id-promise');

const optimizePath = path => idPromise(
// ⚠ use strong identifiers, not just path!
`my-project:optimizePath:${path}`,
Expand Down Expand Up @@ -67,6 +73,9 @@ There are 3 kinds of caveats to consider with this module:
While the first caveat is quite easy to understand, the last one is subtle:

```js
import idPromise from 'id-promise';
// const idPromise = require('id-promise');

const writeOnce = (where, what) => idPromise(
`my-project:writeOnce:${where}`,
(resolve, reject) => {
Expand Down

0 comments on commit 06d0eba

Please sign in to comment.