ciorent 0.11.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/package.json +1 -1
- package/semaphore.d.ts +8 -0
- package/semaphore.js +1 -1
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));
|