You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `options` objects are passed directly to [lru-cache](https://github.com/isaacs/node-lru-cache/tree/9bb53afaf4654dff759e7ece6b092f6c33d036dc#options) allowing you to set the max age, max items, and other behaviors of the LRU cache. When `options.allowStale` is set to `true` the locking cache implements additional behavior to continue serving a stale item until the item has been refreshed in the background.
16
+
17
+
### `Locking(function, options)`
18
+
19
+
For locking callback functions in the form `function(id, callback)`. Returns a callable function
20
+
21
+
```js
22
+
const { Locking } =require('@mapbox/locking');
23
+
constfs=require('fs');
24
+
constreadFile=Locking(fs.readFile, options);
13
25
14
26
// Reads file once, calls callback 10x.
15
-
for (var i =0; i <10; i++) {
16
-
readFile('./sample.txt', function(err, data) {
17
-
console.log(data);
18
-
});
27
+
for (let i =0; i <10; i++) {
28
+
readFile('./sample.txt', function(err, data) {
29
+
console.log(data);
30
+
});
19
31
}
20
32
```
21
33
22
-
`options` is passed directly to [lru-cache](https://github.com/isaacs/node-lru-cache/blob/f25bdae0b4bb0166a75fa01d664a3e3cece1ce98/README.md#options) allowing you to set the max age, max items, and other behaviors of the LRU cache.
34
+
### `LockingAsync(function, options)`
35
+
36
+
Constructor for locking promise or async functions in the form of `function(...arguments)`. This can manage functions of arbitrary arguments and types. Returns a class with two functions, which includes a callable method `get()` for calling the original function.
23
37
24
-
When `options.stale` is set to `true` the locking cache implements additional behavior to continue serving a stale item until the item has been refreshed in the background.
0 commit comments