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
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
27
+
28
+
#### Table of Contents
29
+
30
+
*[atomic](#atomic)
31
+
*[Parameters](#parameters)
32
+
33
+
### atomic
34
+
35
+
[src/index.ts:33-78](https://github.com/stagas/atomic/blob/2a0a9f5694e915eb4fe86dea4895ed398d1458c3/src/index.ts#L33-L78"Source code on GitHub")
36
+
37
+
Makes a function atomic.
38
+
39
+
```js
40
+
constfn=atomic(signal=>async () => {
41
+
// some long async operation
42
+
43
+
// if we've been aborted during the long
44
+
// async process above, we wouldn't want
45
+
// to continue so lets return here
46
+
if (signal.aborted) return
47
+
48
+
// do things here if we didn't abort
49
+
}, 500) // timeout at 500ms (don't pass anything for no timeout)
50
+
fn()
51
+
fn()
52
+
fn()
53
+
awaitfn() // this will run after the above have settled
54
+
```
55
+
56
+
#### Parameters
57
+
58
+
*`signalClosure`**function (signal: AbortSignal): function (...args: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** A function that receives the signal object
59
+
from an AbortController and returns the function to become atomic.
60
+
*`maxTimeMs`**[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Time in milliseconds to timeout the operation. Will also signal abort.
61
+
62
+
Returns **any** An atomic function
27
63
28
64
## Contribute
29
65
30
-
[Fork](https://github.com/stagas/atomic/fork) or
66
+
[Fork](https://github.com/stagas/atomic/fork) or
31
67
[edit](https://github.dev/stagas/atomic) and submit a PR.
0 commit comments