ciorent 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -26
- package/package.json +2 -2
package/README.md
CHANGED
@@ -1,42 +1,18 @@
|
|
1
1
|
A lightweight, low-overhead concurrency library
|
2
2
|
|
3
3
|
# Examples
|
4
|
-
## Semaphore
|
5
|
-
Semaphore is a concurrency primitive used to control access to a common resource by multiple processes.
|
6
|
-
|
7
|
-
```ts
|
8
|
-
import * as semaphore from 'ciorent/semaphore';
|
9
|
-
import * as cio from 'ciorent';
|
10
|
-
|
11
|
-
// Only allow 2 of these tasks to run concurrently
|
12
|
-
const task = semaphore.task(
|
13
|
-
semaphore.init(2),
|
14
|
-
async (task: number) => {
|
15
|
-
for (let i = 1; i <= 5; i++) {
|
16
|
-
console.log('Task', task, 'iteration', i);
|
17
|
-
await cio.pause;
|
18
|
-
}
|
19
|
-
|
20
|
-
console.log('Task', task, 'end');
|
21
|
-
}
|
22
|
-
);
|
23
|
-
|
24
|
-
// Try to run 6 tasks with 4 tasks running concurrently
|
25
|
-
cio.concurrent(6, task, 4);
|
26
|
-
```
|
27
|
-
|
28
4
|
## Channel
|
29
5
|
Channel is a synchronization primitive via message passing. A message may be sent over a channel, and another process is able to receive messages sent over a channel it has a reference to.
|
30
6
|
|
31
7
|
```ts
|
32
8
|
import * as channel from 'ciorent/channel';
|
9
|
+
import * as cio from 'ciorent';
|
33
10
|
|
34
11
|
const c = channel.init<number>();
|
35
|
-
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
36
12
|
|
37
13
|
const run = async () => {
|
38
14
|
for (let i = 0; i < 10; i++) {
|
39
|
-
await sleep(10);
|
15
|
+
await cio.sleep(10);
|
40
16
|
channel.send(c, i);
|
41
17
|
console.log('Sent', i);
|
42
18
|
}
|
@@ -66,6 +42,30 @@ log();
|
|
66
42
|
console.log('Starting...');
|
67
43
|
```
|
68
44
|
|
45
|
+
## Semaphore
|
46
|
+
Semaphore is a concurrency primitive used to control access to a common resource by multiple processes.
|
47
|
+
|
48
|
+
```ts
|
49
|
+
import * as semaphore from 'ciorent/semaphore';
|
50
|
+
import * as cio from 'ciorent';
|
51
|
+
|
52
|
+
// Only allow 2 of these tasks to run concurrently
|
53
|
+
const task = semaphore.task(
|
54
|
+
semaphore.init(2),
|
55
|
+
async (task: number) => {
|
56
|
+
for (let i = 1; i <= 5; i++) {
|
57
|
+
console.log('Task', task, 'iteration', i);
|
58
|
+
await cio.pause;
|
59
|
+
}
|
60
|
+
|
61
|
+
console.log('Task', task, 'end');
|
62
|
+
}
|
63
|
+
);
|
64
|
+
|
65
|
+
// Try to run 6 tasks with 4 tasks running concurrently
|
66
|
+
cio.concurrent(6, task, 4);
|
67
|
+
```
|
68
|
+
|
69
69
|
## Latch
|
70
70
|
Latch is a synchronization primitive that allows one process to wait until another completes an operation before continuing execution.
|
71
71
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ciorent",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.12",
|
4
4
|
"description": "A lightweight, low-overhead concurrency library",
|
5
5
|
"homepage": "https://ciorent.netlify.app",
|
6
6
|
"repository": {
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"types": "./index.d.ts",
|
20
20
|
"scripts": {
|
21
21
|
"task": "bun scripts/task.ts",
|
22
|
-
"build:test": "bun
|
22
|
+
"build:test": "bun task build && bun docs && bun test",
|
23
23
|
"build:publish": "bun build:test && bun task report-size && bun task publish",
|
24
24
|
"lint": "eslint ./src",
|
25
25
|
"lint:fix": "eslint ./src --fix",
|