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 CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Describe a latch
3
3
  */
4
- export type Latch = [p: Promise<void>, res: () => void, cb: (res: () => void) => 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ciorent",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "A lightweight, low-overhead concurrency library",
5
5
  "homepage": "https://re-utils.pages.dev/concurrency",
6
6
  "repository": {
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 t=[,];let n=[t,t,e,e=>{n[0]=n[0][0]=[,e]}];return n};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]()};
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));