Skip to content

Commit 96cebf6

Browse files
committed
version 1.0.0
1 parent 2a0a9f5 commit 96cebf6

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

README.md

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1 align="center">atomic</h1>
22

33
<p align="center">
4-
Atomic operations
4+
makes a function atomic with timeout and abort signal
55
</p>
66

77
<p align="center">
@@ -13,7 +13,7 @@ Atomic operations
1313
· <a href="https://github.com/stagas/atomic/issues"> 🖐️ <strong>Help</strong></a>
1414
</p>
1515

16-
---
16+
***
1717

1818
## Install
1919

@@ -23,16 +23,52 @@ $ npm i atomic
2323

2424
## API
2525

26-
wip
26+
<!-- 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+
const fn = 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+
await fn() // 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
2763

2864
## Contribute
2965

30-
[Fork](https://github.com/stagas/atomic/fork) or
66+
[Fork](https://github.com/stagas/atomic/fork) or
3167
[edit](https://github.dev/stagas/atomic) and submit a PR.
3268

3369
All contributions are welcome!
3470

3571
## License
3672

37-
MIT &copy; 2022
73+
MIT © 2022
3874
[stagas](https://github.com/stagas)

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
"author": "stagas",
44
"short": "stagas/atomic",
55
"description": "makes a function atomic with timeout and abort signal",
6-
"version": "0.0.0",
6+
"version": "1.0.0",
77
"license": "MIT",
88
"repository": {
99
"type": "git",
1010
"url": "git+https://[email protected]:stagas/atomic.git"
1111
},
12-
"keywords": [],
12+
"keywords": [
13+
"atomic",
14+
"promise",
15+
"concurrency",
16+
"timeout",
17+
"signal",
18+
"abort",
19+
"race-conditions"
20+
],
1321
"module": "dist/esm/index.js",
1422
"main": "dist/cjs/index.js",
1523
"exports": {

0 commit comments

Comments
 (0)