ciorent 0.0.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/README.md +2 -0
- package/channel.d.ts +60 -0
- package/channel.js +1 -0
- package/index.d.ts +8 -0
- package/index.js +1 -0
- package/package.json +29 -0
package/README.md
ADDED
package/channel.d.ts
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
/**
|
2
|
+
* @module
|
3
|
+
* Channels
|
4
|
+
*/
|
5
|
+
type QueueNode<T> = [T, QueueNode<T> | null];
|
6
|
+
/**
|
7
|
+
* Describe a channel
|
8
|
+
*/
|
9
|
+
export interface Channel<T> {
|
10
|
+
/**
|
11
|
+
* Opening state of the channel
|
12
|
+
*/
|
13
|
+
0: boolean;
|
14
|
+
/**
|
15
|
+
* The head of the value queue
|
16
|
+
*/
|
17
|
+
1: QueueNode<Promise<T | typeof closed>>;
|
18
|
+
/**
|
19
|
+
* The tail of the value queue
|
20
|
+
*/
|
21
|
+
2: QueueNode<Promise<T | typeof closed>>;
|
22
|
+
/**
|
23
|
+
* The head of the Promise resolve queue
|
24
|
+
*/
|
25
|
+
3: QueueNode<(value: Promise<T | typeof closed> | T | typeof closed) => void>;
|
26
|
+
/**
|
27
|
+
* The tail of the Promise resolve queue
|
28
|
+
*/
|
29
|
+
4: QueueNode<(value: Promise<T | typeof closed> | T | typeof closed) => void>;
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* A signal that means the channel has closed
|
33
|
+
*/
|
34
|
+
export declare const closed: unique symbol;
|
35
|
+
/**
|
36
|
+
* Create a channel
|
37
|
+
*/
|
38
|
+
export declare const init: <T>() => Channel<T>;
|
39
|
+
/**
|
40
|
+
* Send a message to a channel
|
41
|
+
* @param c - The channel to send to
|
42
|
+
* @param t - The message to send
|
43
|
+
*/
|
44
|
+
export declare const send: <T>(c: Channel<T>, t: Promise<T> | T) => void;
|
45
|
+
/**
|
46
|
+
* Recieve a message from a channel
|
47
|
+
* @param c
|
48
|
+
*/
|
49
|
+
export declare const recieve: <T>(c: Channel<T>) => Promise<T | typeof closed>;
|
50
|
+
/**
|
51
|
+
* Close a channel
|
52
|
+
* @param c
|
53
|
+
*/
|
54
|
+
export declare const close: <T>(c: Channel<T>) => void;
|
55
|
+
/**
|
56
|
+
* Check whether a channel is still open yet
|
57
|
+
* @param c
|
58
|
+
*/
|
59
|
+
export declare const active: (c: Channel<any>) => boolean;
|
60
|
+
export {};
|
package/channel.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export let closed=Symbol();let closedPromise=Promise.resolve(closed);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 instanceof Promise?t:Promise.resolve(t),null]}};export let recieve=(c)=>c[2][1]!==null?(c[2]=c[2][1])[0]:c[0]?new Promise((res)=>{c[3]=c[3][1]=[res,null]}):closedPromise;export let close=(c)=>{c[0]=false;while(c[4][1]!==null)(c[4]=c[4][1])[0](closed)};export let active=(c)=>c[0];
|
package/index.d.ts
ADDED
package/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export let pause=Promise.resolve();
|
package/package.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"name": "ciorent",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "A concurrency library",
|
5
|
+
"keywords": [],
|
6
|
+
"license": "MIT",
|
7
|
+
"type": "module",
|
8
|
+
"main": "./index.js",
|
9
|
+
"types": "./index.d.ts",
|
10
|
+
"scripts": {
|
11
|
+
"task": "bun scripts/task.ts",
|
12
|
+
"build:test": "bun task build && bun test",
|
13
|
+
"build:publish": "bun task build && bun task report-size && bun task publish",
|
14
|
+
"lint": "eslint ./src",
|
15
|
+
"lint:fix": "eslint ./src --fix"
|
16
|
+
},
|
17
|
+
"devDependencies": {
|
18
|
+
"@stylistic/eslint-plugin": "latest",
|
19
|
+
"@types/bun": "latest",
|
20
|
+
"@types/uglify-js": "latest",
|
21
|
+
"eslint": "latest",
|
22
|
+
"eslint-plugin-jsdoc": "latest",
|
23
|
+
"mitata": "latest",
|
24
|
+
"tsx": "latest",
|
25
|
+
"typescript": "latest",
|
26
|
+
"typescript-eslint": "latest",
|
27
|
+
"uglify-js": "latest"
|
28
|
+
}
|
29
|
+
}
|