ciorent 0.0.9 → 0.0.11

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 CHANGED
@@ -1,4 +1,4 @@
1
- A low-overhead, cross-runtime concurrency library.
1
+ A lightweight, low-overhead concurrency library
2
2
 
3
3
  # Examples
4
4
  ## Semaphore
@@ -51,8 +51,9 @@ const log = async () => {
51
51
  // Non-blocking
52
52
  const x = await channel.recieve(c);
53
53
 
54
- // If the channel has been closed
55
- if (x === null) break;
54
+ // 'recieve' returns undefined if
55
+ // The channel has been closed
56
+ if (x == null) break;
56
57
 
57
58
  console.log('Recieved', x);
58
59
  };
@@ -179,7 +180,7 @@ console.log('Running sequentially:');
179
180
  cio.sequential(5, task);
180
181
 
181
182
  // Spawn and run 5 tasks concurrently
182
- console.log('Running concurrently:');
183
+ console.log('Running 5 tasks concurrently:');
183
184
  cio.concurrent(5, task);
184
185
 
185
186
  // Spawn and run 5 tasks, with the maximum
package/channel.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  /**
2
- * @module
3
- * Channels
2
+ * @module Channels
4
3
  */
5
- import type { QueueNode } from './queue';
4
+ import type { QueueNode } from './fixed-queue';
6
5
  /**
7
6
  * Describe a channel
8
7
  */
@@ -22,11 +21,11 @@ export interface Channel<T> {
22
21
  /**
23
22
  * The head of the Promise resolve queue
24
23
  */
25
- 3: QueueNode<(value: T | null) => void>;
24
+ 3: QueueNode<(value?: T) => void>;
26
25
  /**
27
26
  * The tail of the Promise resolve queue
28
27
  */
29
- 4: QueueNode<(value: T | null) => void>;
28
+ 4: QueueNode<(value?: T) => void>;
30
29
  }
31
30
  /**
32
31
  * Create a channel
@@ -42,12 +41,12 @@ export declare const send: <T>(c: Channel<T>, t: T) => void;
42
41
  * Recieve a message from a channel, return null if the channel is closed
43
42
  * @param c
44
43
  */
45
- export declare const recieve: <T>(c: Channel<T>) => Promise<T | null>;
44
+ export declare const recieve: <T>(c: Channel<T>) => Promise<T | undefined>;
46
45
  /**
47
46
  * Recieve a message from a channel, return null if no message is currently in queue
48
47
  * @param c
49
48
  */
50
- export declare const poll: <T>(c: Channel<T>) => T | null;
49
+ export declare const poll: <T>(c: Channel<T>) => T | undefined;
51
50
  /**
52
51
  * Close a channel
53
52
  * @param c
package/channel.js CHANGED
@@ -1 +1 @@
1
- let resolvedNull=Promise.resolve(null);export let init=()=>{let qu=[null,null];let resolveQu=[null,null];return[true,qu,qu,resolveQu,resolveQu]};export let send=(c,t)=>{if(c[0]){if(c[4][1]!==null)(c[4]=c[4][1])[0](t);else c[1]=c[1][1]=[t,null]}};export let recieve=(c)=>c[2][1]!==null?Promise.resolve((c[2]=c[2][1])[0]):c[0]?new Promise((res)=>{c[3]=c[3][1]=[res,null]}):resolvedNull;export let poll=(c)=>c[2][1]!==null?(c[2]=c[2][1])[0]:null;export let close=(c)=>{c[0]=false;while(c[4][1]!==null)(c[4]=c[4][1])[0](null)};export let active=(c)=>c[0];
1
+ import{pause as resolvedPromise}from".";export let init=()=>{let qu=[null,null];let resolveQu=[null,null];return[true,qu,qu,resolveQu,resolveQu]};export let send=(c,t)=>{if(c[0]){if(c[4][1]!==null)(c[4]=c[4][1])[0](t);else c[1]=c[1][1]=[t,null]}};export let recieve=(c)=>c[2][1]!==null?Promise.resolve((c[2]=c[2][1])[0]):c[0]?new Promise((res)=>{c[3]=c[3][1]=[res,null]}):resolvedPromise;export let poll=(c)=>c[2][1]!==null?(c[2]=c[2][1])[0]:undefined;export let close=(c)=>{c[0]=false;while(c[4][1]!==null)(c[4]=c[4][1])[0]()};export let active=(c)=>c[0];
package/concurrent.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * @module
3
- * Concurrency controls
2
+ * @module Concurrency controls
4
3
  */
5
4
  /**
6
5
  * Describe a concurrency controller
@@ -1,10 +1,9 @@
1
1
  /**
2
- * @module
3
- * Dropping queues
2
+ * @module Dropping queues
4
3
  */
5
- import type { FixedQueue } from '.';
6
- export { default as init } from '.';
7
- export { pop } from './sliding';
4
+ import type { FixedQueue } from './fixed-queue';
5
+ export { default as init } from './fixed-queue';
6
+ export { pop } from './sliding-queue';
8
7
  /**
9
8
  * Push an item to a dropping queue
10
9
  * @param q - The queue to push to
@@ -0,0 +1 @@
1
+ export{default as init}from"./fixed-queue";export{pop}from"./sliding-queue";export let push=(q,item)=>{if(q[0][(q[2]+1)%q[1]]!=null)return false;q[0][q[2]=(q[2]+1)%q[1]]=item;return true};
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * @private
3
- * @module
4
- * Queue utilities
3
+ * @module Queue utilities
5
4
  */
6
5
  /**
7
6
  * Describe a fixed-sized queue
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * @module
3
- * Other utilities
2
+ * @module Other utilities
4
3
  */
5
4
  /**
6
5
  * Continue running the function on next microtask.
package/latch.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * @module
3
- * Latches
2
+ * @module Latches
4
3
  */
5
4
  /**
6
5
  * Describe a latch
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ciorent",
3
- "version": "0.0.9",
4
- "description": "A low-overhead, lightweight concurrency library",
3
+ "version": "0.0.11",
4
+ "description": "A lightweight, low-overhead concurrency library",
5
5
  "homepage": "https://ciorent.netlify.app",
6
6
  "repository": {
7
7
  "type": "github",
@@ -10,7 +10,8 @@
10
10
  "keywords": [
11
11
  "low-overhead",
12
12
  "lightweight",
13
- "concurrency"
13
+ "concurrency",
14
+ "cross-runtime"
14
15
  ],
15
16
  "license": "MIT",
16
17
  "type": "module",
@@ -22,7 +23,7 @@
22
23
  "build:publish": "bun build:test && bun task report-size && bun task publish",
23
24
  "lint": "eslint ./src",
24
25
  "lint:fix": "eslint ./src --fix",
25
- "docs": "typedoc ./src/** --entryPointStrategy Expand --plugin typedoc-material-theme --skipErrorChecking"
26
+ "docs": "typedoc"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@stylistic/eslint-plugin": "latest",
@@ -35,6 +36,7 @@
35
36
  "tsx": "latest",
36
37
  "typedoc": "^0.27.9",
37
38
  "typedoc-material-theme": "^1.3.0",
39
+ "typedoc-plugin-inline-sources": "^1.2.1",
38
40
  "typescript": "latest",
39
41
  "typescript-eslint": "latest"
40
42
  }
package/semaphore.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  /**
2
- * @module
3
- * Semaphores
2
+ * @module Semaphores
4
3
  */
5
- import type { QueueNode } from './queue';
4
+ import type { QueueNode } from './fixed-queue';
6
5
  /**
7
6
  * Describe a semaphore
8
7
  */
@@ -1,9 +1,8 @@
1
1
  /**
2
- * @module
3
- * Sliding queues
2
+ * @module Sliding queues
4
3
  */
5
- import type { FixedQueue } from '.';
6
- export { default as init } from '.';
4
+ import type { FixedQueue } from './fixed-queue';
5
+ export { default as init } from './fixed-queue';
7
6
  /**
8
7
  * Push an item to a sliding queue
9
8
  * @param q - The queue to push to
@@ -0,0 +1 @@
1
+ export{default as init}from"./fixed-queue";export let push=(q,item)=>{q[0][q[2]=(q[2]+1)%q[1]]=item};export let pop=(q)=>{let val=q[0][(q[3]+1)%q[1]];if(val!=null){q[0][q[3]=(q[3]+1)%q[1]]=null;return val}};
package/queue/dropping.js DELETED
@@ -1 +0,0 @@
1
- export{default as init}from".";export{pop}from"./sliding";export let push=(q,item)=>{if(q[0][(q[2]+1)%q[1]]!=null)return false;q[0][q[2]=(q[2]+1)%q[1]]=item;return true};
package/queue/sliding.js DELETED
@@ -1 +0,0 @@
1
- export{default as init}from".";export let push=(q,item)=>{q[0][q[2]=(q[2]+1)%q[1]]=item};export let pop=(q)=>{let val=q[0][(q[3]+1)%q[1]];if(val!=null){q[0][q[3]=(q[3]+1)%q[1]]=null;return val}};
File without changes