ciorent 0.3.1 → 0.3.2
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 +1 -1
- package/defer.d.ts +22 -0
- package/defer.js +1 -0
- package/latch.d.ts +4 -7
- package/latch.js +1 -1
- package/package.json +9 -8
package/README.md
CHANGED
@@ -181,7 +181,7 @@ const startFetch = latch.init();
|
|
181
181
|
|
182
182
|
const task = async () => {
|
183
183
|
// Blocks until the latch is open
|
184
|
-
await latch.
|
184
|
+
await latch.wait(startFetch);
|
185
185
|
|
186
186
|
console.log('Start fetching...');
|
187
187
|
const res = await fetch('http://example.com');
|
package/defer.d.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* @module Deferred values
|
3
|
+
*/
|
4
|
+
/**
|
5
|
+
* Describe a defer
|
6
|
+
*/
|
7
|
+
export type Defer<T = any> = [
|
8
|
+
pause: Promise<T>,
|
9
|
+
open: (value: T | PromiseLike<T>) => void
|
10
|
+
];
|
11
|
+
/**
|
12
|
+
* Create a latch
|
13
|
+
*/
|
14
|
+
export declare const init: <T>() => Defer<T>;
|
15
|
+
/**
|
16
|
+
* Pause until a deferred is resolved
|
17
|
+
*/
|
18
|
+
export declare const wait: <T>(d: Defer<T>) => Promise<T>;
|
19
|
+
/**
|
20
|
+
* Open a latch
|
21
|
+
*/
|
22
|
+
export declare const resolve: <T>(d: Defer<T>, p: T | PromiseLike<T>) => void;
|
package/defer.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export let init=()=>{let r;return[new Promise((res)=>{r=res}),r]};export let wait=(d)=>d[0];export let resolve=(d,p)=>{d[1](p)};
|
package/latch.d.ts
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
/**
|
2
2
|
* @module Latches
|
3
3
|
*/
|
4
|
+
import { type Defer } from './defer.js';
|
4
5
|
/**
|
5
6
|
* Describe a latch
|
6
7
|
*/
|
7
|
-
export type Latch =
|
8
|
+
export type Latch = Defer<void>;
|
8
9
|
/**
|
9
10
|
* Create a latch
|
10
11
|
*/
|
11
12
|
export declare const init: () => Latch;
|
12
13
|
/**
|
13
|
-
*
|
14
|
+
* Wait until a latch is opened
|
14
15
|
*/
|
15
|
-
export declare const
|
16
|
+
export declare const wait: (d: Latch) => Promise<void>;
|
16
17
|
/**
|
17
18
|
* Open a latch
|
18
19
|
*/
|
19
20
|
export declare const open: (latch: Latch) => void;
|
20
|
-
/**
|
21
|
-
* Close a latch
|
22
|
-
*/
|
23
|
-
export declare const close: (latch: Latch) => void;
|
package/latch.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{
|
1
|
+
import{init as deferInit,wait as deferWait}from"./defer.js";export let init=deferInit;export let wait=deferWait;export let open=(latch)=>{latch[1]()};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ciorent",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.2",
|
4
4
|
"description": "A lightweight, low-overhead concurrency library",
|
5
5
|
"homepage": "https://ciorent.netlify.app",
|
6
6
|
"repository": {
|
@@ -18,15 +18,16 @@
|
|
18
18
|
"main": "./index.js",
|
19
19
|
"types": "./index.d.ts",
|
20
20
|
"exports": {
|
21
|
-
"./latch": "./latch.js",
|
22
|
-
"./dropping-queue": "./dropping-queue.js",
|
23
|
-
"./sliding-queue": "./sliding-queue.js",
|
24
|
-
"./channel": "./channel.js",
|
25
|
-
"./fiber": "./fiber.js",
|
26
|
-
"./lock": "./lock.js",
|
27
21
|
"./queue": "./queue.js",
|
28
22
|
"./topic": "./topic.js",
|
23
|
+
"./sliding-queue": "./sliding-queue.js",
|
24
|
+
"./lock": "./lock.js",
|
25
|
+
"./latch": "./latch.js",
|
26
|
+
"./defer": "./defer.js",
|
29
27
|
"./semaphore": "./semaphore.js",
|
30
|
-
"
|
28
|
+
"./dropping-queue": "./dropping-queue.js",
|
29
|
+
"./channel": "./channel.js",
|
30
|
+
".": "./index.js",
|
31
|
+
"./fiber": "./fiber.js"
|
31
32
|
}
|
32
33
|
}
|