@nxtedition/yield 1.0.6 → 1.0.7
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/lib/index.d.ts +4 -2
- package/lib/index.js +29 -9
- package/package.json +4 -3
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ type Dispatcher = (callback: () => void) => void;
|
|
|
2
2
|
export declare function setYieldDispatcher(schedule: Dispatcher | null): void;
|
|
3
3
|
export declare function setYieldTimeout(timeout: number): void;
|
|
4
4
|
export declare function shouldYield(timeout?: number): boolean;
|
|
5
|
-
export declare function maybeYield<T>(callback
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function maybeYield<T>(callback: (opaque: T | undefined) => void, opaque?: T, timeout?: number): void;
|
|
6
|
+
export declare function maybeYield(timeout?: number): Promise<void> | null;
|
|
7
|
+
export declare function doYield<T>(callback: (opaque: T | undefined) => void, opaque?: T): void;
|
|
8
|
+
export declare function doYield(): Promise<void>;
|
|
7
9
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -34,26 +34,47 @@ export function shouldYield(timeout ) {
|
|
|
34
34
|
return yieldActive
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
37
43
|
export function maybeYield (
|
|
38
|
-
|
|
44
|
+
callbackOrTimeout ,
|
|
39
45
|
opaque ,
|
|
40
46
|
timeout ,
|
|
41
|
-
)
|
|
47
|
+
) {
|
|
48
|
+
const callback = typeof callbackOrTimeout === 'function' ? callbackOrTimeout : undefined
|
|
49
|
+
if (timeout === undefined && typeof callbackOrTimeout === 'number') {
|
|
50
|
+
timeout = callbackOrTimeout
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
if (callback != null && typeof callback !== 'function') {
|
|
43
54
|
throw new TypeError('callback must be a function')
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
if (shouldYield(timeout)) {
|
|
47
|
-
|
|
58
|
+
if (callback != null) {
|
|
59
|
+
doYield(callback, opaque)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
return doYield()
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
if (callback != null) {
|
|
51
66
|
callback(opaque)
|
|
67
|
+
return
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
return null
|
|
55
71
|
}
|
|
56
72
|
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
57
78
|
export function doYield (
|
|
58
79
|
callback ,
|
|
59
80
|
opaque ,
|
|
@@ -67,14 +88,13 @@ export function doYield (
|
|
|
67
88
|
yieldSchedule(dispatchYield)
|
|
68
89
|
}
|
|
69
90
|
|
|
70
|
-
if (callback
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
if (callback == null) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
yieldQueue.push(resolve, null)
|
|
94
|
+
})
|
|
73
95
|
}
|
|
74
96
|
|
|
75
|
-
|
|
76
|
-
yieldQueue.push(resolve, null)
|
|
77
|
-
})
|
|
97
|
+
yieldQueue.push(callback, opaque)
|
|
78
98
|
}
|
|
79
99
|
|
|
80
100
|
function dispatchYield() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/yield",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"test:ci": "node --test"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.2.3",
|
|
19
20
|
"amaroc": "^1.0.1",
|
|
21
|
+
"oxlint-tsgolint": "^0.12.2",
|
|
20
22
|
"rimraf": "^6.1.2",
|
|
21
23
|
"typescript": "^5.9.3"
|
|
22
|
-
}
|
|
23
|
-
"gitHead": "dc18f1fb0cf53929205b2de3cb53c08b631a4a9d"
|
|
24
|
+
}
|
|
24
25
|
}
|