ciorent 0.10.0 → 0.11.1
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/latch.d.ts +2 -2
- package/latch.js +1 -1
- package/package.json +1 -1
- package/semaphore.d.ts +8 -0
- package/semaphore.js +1 -1
package/latch.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Describe a latch
|
3
3
|
*/
|
4
|
-
export type Latch = [p: Promise<void
|
4
|
+
export type Latch = [p: Promise<void> | void, res: () => void, cb: (res: () => void) => void];
|
5
5
|
export declare const init: <T>() => Latch;
|
6
6
|
/**
|
7
7
|
* Reclose the latch
|
@@ -17,4 +17,4 @@ export declare const open: (c: Latch) => void;
|
|
17
17
|
* Wait for the latch to open
|
18
18
|
* @param c
|
19
19
|
*/
|
20
|
-
export declare const wait: (c: Latch) => Promise<void
|
20
|
+
export declare const wait: (c: Latch) => Promise<void> | void;
|
package/latch.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export let init=()=>{let e=[,,r=>{e[1]=r}];close(e);return e};export let close=e=>{e[0]=new Promise(e[2])};export let open=e=>{e[1]()};export let wait=e=>e[0];
|
1
|
+
export let init=()=>{let e=[,,r=>{e[1]=r}];close(e);return e};export let close=e=>{if(e[0]==null)e[0]=new Promise(e[2])};export let open=e=>{e[1]();e[0]=void 0};export let wait=e=>e[0];
|
package/package.json
CHANGED
package/semaphore.d.ts
CHANGED
@@ -21,3 +21,11 @@ export declare const acquire: (s: Semaphore) => Promise<void> | void;
|
|
21
21
|
* Signal to the semaphore to release access
|
22
22
|
*/
|
23
23
|
export declare const release: (s: Semaphore) => void;
|
24
|
+
/**
|
25
|
+
* Control concurrency of a task with a semaphore
|
26
|
+
*/
|
27
|
+
export declare const control: <T extends () => Promise<any>>(task: T, s: Semaphore) => T;
|
28
|
+
/**
|
29
|
+
* Set maximum concurrency for a task
|
30
|
+
*/
|
31
|
+
export declare const permits: <T extends () => Promise<any>>(task: T, permits: number) => T;
|
package/semaphore.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export let init=e=>{let
|
1
|
+
export let init=e=>{let n=[,];let r=[n,n,e,e=>{r[0]=r[0][0]=[,e]}];return r};export let acquire=e=>{if(--e[2]<0)return new Promise(e[3])};export let release=e=>{if(e[2]++<0)(e[1]=e[1][0])[1]()};export let control=(e,n)=>async(...i)=>{if(--n[2]<0)await new Promise(n[3]);try{return await e(...i)}finally{release(n)}};export let permits=(n,r)=>control(n,init(r));
|