@naturalcycles/js-lib 14.105.0 → 14.105.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/dist/promise/pDefer.js +1 -0
- package/dist/promise/pDelay.js +1 -1
- package/dist/promise/pHang.js +1 -1
- package/dist/promise/pMap.js +1 -1
- package/dist/promise/pQueue.js +5 -5
- package/dist/promise/pState.js +1 -1
- package/dist-esm/promise/pDefer.js +1 -0
- package/dist-esm/promise/pDelay.js +1 -1
- package/dist-esm/promise/pHang.js +1 -1
- package/dist-esm/promise/pMap.js +1 -1
- package/dist-esm/promise/pQueue.js +5 -5
- package/dist-esm/promise/pState.js +1 -1
- package/package.json +4 -3
- package/src/promise/pDefer.ts +2 -0
- package/src/promise/pDelay.ts +1 -1
- package/src/promise/pHang.ts +1 -1
- package/src/promise/pMap.ts +1 -1
- package/src/promise/pQueue.ts +5 -5
- package/src/promise/pState.ts +1 -1
package/dist/promise/pDefer.js
CHANGED
package/dist/promise/pDelay.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pDelay = void 0;
|
|
4
4
|
async function pDelay(ms = 0, value) {
|
|
5
|
-
return new Promise(resolve => setTimeout(() => resolve(value), ms));
|
|
5
|
+
return await new Promise(resolve => setTimeout(() => resolve(value), ms));
|
|
6
6
|
}
|
|
7
7
|
exports.pDelay = pDelay;
|
package/dist/promise/pHang.js
CHANGED
package/dist/promise/pMap.js
CHANGED
package/dist/promise/pQueue.js
CHANGED
|
@@ -39,18 +39,18 @@ class PQueue {
|
|
|
39
39
|
* Resolves immediately in case the queue is Idle.
|
|
40
40
|
* Idle means 0 queue and 0 inFlight.
|
|
41
41
|
*/
|
|
42
|
-
onIdle() {
|
|
42
|
+
async onIdle() {
|
|
43
43
|
if (this.queue.length === 0 && this.inFlight === 0)
|
|
44
|
-
return
|
|
44
|
+
return;
|
|
45
45
|
const listener = (0, pDefer_1.pDefer)();
|
|
46
46
|
this.onIdleListeners.push(listener);
|
|
47
|
-
return listener;
|
|
47
|
+
return await listener;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Push PromiseReturningFunction to the Queue.
|
|
51
51
|
* Returns a Promise that resolves (or rejects) with the return value from the Promise.
|
|
52
52
|
*/
|
|
53
|
-
push(fn_) {
|
|
53
|
+
async push(fn_) {
|
|
54
54
|
const { concurrency } = this.cfg;
|
|
55
55
|
const resolveOnStart = this.cfg.resolveOn === 'start';
|
|
56
56
|
const fn = fn_;
|
|
@@ -99,7 +99,7 @@ class PQueue {
|
|
|
99
99
|
this.queue.push(fn);
|
|
100
100
|
this.debug(`inFlight ${this.inFlight}/${concurrency}, queue++ ${this.queue.length}`);
|
|
101
101
|
}
|
|
102
|
-
return fn.defer;
|
|
102
|
+
return await fn.defer;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
exports.PQueue = PQueue;
|
package/dist/promise/pState.js
CHANGED
|
@@ -11,7 +11,7 @@ const UNIQUE_VALUE = Symbol('unique');
|
|
|
11
11
|
* Based on: https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-native-promise
|
|
12
12
|
*/
|
|
13
13
|
async function pState(p) {
|
|
14
|
-
return Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => {
|
|
14
|
+
return await Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => {
|
|
15
15
|
return v === UNIQUE_VALUE ? 'pending' : 'resolved';
|
|
16
16
|
}, () => 'rejected');
|
|
17
17
|
}
|
package/dist-esm/promise/pMap.js
CHANGED
|
@@ -31,18 +31,18 @@ export class PQueue {
|
|
|
31
31
|
* Resolves immediately in case the queue is Idle.
|
|
32
32
|
* Idle means 0 queue and 0 inFlight.
|
|
33
33
|
*/
|
|
34
|
-
onIdle() {
|
|
34
|
+
async onIdle() {
|
|
35
35
|
if (this.queue.length === 0 && this.inFlight === 0)
|
|
36
|
-
return
|
|
36
|
+
return;
|
|
37
37
|
const listener = pDefer();
|
|
38
38
|
this.onIdleListeners.push(listener);
|
|
39
|
-
return listener;
|
|
39
|
+
return await listener;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Push PromiseReturningFunction to the Queue.
|
|
43
43
|
* Returns a Promise that resolves (or rejects) with the return value from the Promise.
|
|
44
44
|
*/
|
|
45
|
-
push(fn_) {
|
|
45
|
+
async push(fn_) {
|
|
46
46
|
const { concurrency } = this.cfg;
|
|
47
47
|
const resolveOnStart = this.cfg.resolveOn === 'start';
|
|
48
48
|
const fn = fn_;
|
|
@@ -91,6 +91,6 @@ export class PQueue {
|
|
|
91
91
|
this.queue.push(fn);
|
|
92
92
|
this.debug(`inFlight ${this.inFlight}/${concurrency}, queue++ ${this.queue.length}`);
|
|
93
93
|
}
|
|
94
|
-
return fn.defer;
|
|
94
|
+
return await fn.defer;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -8,7 +8,7 @@ const UNIQUE_VALUE = Symbol('unique');
|
|
|
8
8
|
* Based on: https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-native-promise
|
|
9
9
|
*/
|
|
10
10
|
export async function pState(p) {
|
|
11
|
-
return Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => {
|
|
11
|
+
return await Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => {
|
|
12
12
|
return v === UNIQUE_VALUE ? 'pending' : 'resolved';
|
|
13
13
|
}, () => 'rejected');
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.105.
|
|
3
|
+
"version": "14.105.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@naturalcycles/bench-lib": "^1.5.0",
|
|
15
|
-
"@naturalcycles/dev-lib": "^
|
|
15
|
+
"@naturalcycles/dev-lib": "^13.0.1",
|
|
16
16
|
"@naturalcycles/nodejs-lib": "^12.33.4",
|
|
17
17
|
"@naturalcycles/time-lib": "^3.5.1",
|
|
18
|
-
"@types/node": "^
|
|
18
|
+
"@types/node": "^18.0.0",
|
|
19
|
+
"expect-type": "^0.13.0",
|
|
19
20
|
"jest": "^28.0.3",
|
|
20
21
|
"patch-package": "^6.2.1",
|
|
21
22
|
"prettier": "^2.1.2",
|
package/src/promise/pDefer.ts
CHANGED
package/src/promise/pDelay.ts
CHANGED
package/src/promise/pHang.ts
CHANGED
package/src/promise/pMap.ts
CHANGED
package/src/promise/pQueue.ts
CHANGED
|
@@ -94,19 +94,19 @@ export class PQueue {
|
|
|
94
94
|
* Resolves immediately in case the queue is Idle.
|
|
95
95
|
* Idle means 0 queue and 0 inFlight.
|
|
96
96
|
*/
|
|
97
|
-
onIdle(): Promise<void> {
|
|
98
|
-
if (this.queue.length === 0 && this.inFlight === 0) return
|
|
97
|
+
async onIdle(): Promise<void> {
|
|
98
|
+
if (this.queue.length === 0 && this.inFlight === 0) return
|
|
99
99
|
|
|
100
100
|
const listener = pDefer()
|
|
101
101
|
this.onIdleListeners.push(listener)
|
|
102
|
-
return listener
|
|
102
|
+
return await listener
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Push PromiseReturningFunction to the Queue.
|
|
107
107
|
* Returns a Promise that resolves (or rejects) with the return value from the Promise.
|
|
108
108
|
*/
|
|
109
|
-
push<R>(fn_: PromiseReturningFunction<R>): Promise<R> {
|
|
109
|
+
async push<R>(fn_: PromiseReturningFunction<R>): Promise<R> {
|
|
110
110
|
const { concurrency } = this.cfg
|
|
111
111
|
const resolveOnStart = this.cfg.resolveOn === 'start'
|
|
112
112
|
|
|
@@ -155,6 +155,6 @@ export class PQueue {
|
|
|
155
155
|
this.debug(`inFlight ${this.inFlight}/${concurrency}, queue++ ${this.queue.length}`)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
return fn.defer
|
|
158
|
+
return await fn.defer
|
|
159
159
|
}
|
|
160
160
|
}
|
package/src/promise/pState.ts
CHANGED
|
@@ -9,7 +9,7 @@ const UNIQUE_VALUE = Symbol('unique')
|
|
|
9
9
|
* Based on: https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-native-promise
|
|
10
10
|
*/
|
|
11
11
|
export async function pState(p: Promise<any>): Promise<'resolved' | 'rejected' | 'pending'> {
|
|
12
|
-
return Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(
|
|
12
|
+
return await Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(
|
|
13
13
|
v => {
|
|
14
14
|
return v === UNIQUE_VALUE ? 'pending' : 'resolved'
|
|
15
15
|
},
|