more-proms 1.6.0 → 1.7.0
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.
|
@@ -3,6 +3,7 @@ type P<Args extends unknown[], Ret> = {
|
|
|
3
3
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): P<Args, Ret | TResult>;
|
|
4
4
|
} & ((...a: Args) => (CancelAblePromise<Ret> | Promise<Ret> | undefined));
|
|
5
5
|
export declare function latestLatent<Args extends unknown[], Ret>(cb: (...args: Args) => (CancelAblePromise<Ret> | Promise<Ret> | undefined)): P<Args, Ret>;
|
|
6
|
+
export declare function execQueue(): <T>(f: () => Promise<T>) => ResablePromise<void>;
|
|
6
7
|
export declare class SyncPromise<T = unknown> {
|
|
7
8
|
private thenListener;
|
|
8
9
|
private catchListener;
|
|
@@ -43,6 +43,34 @@ function latestLatent(cb) {
|
|
|
43
43
|
propagateFuture(request, futures, "catch", prom);
|
|
44
44
|
return request;
|
|
45
45
|
}
|
|
46
|
+
function execQueue() {
|
|
47
|
+
const queue = [];
|
|
48
|
+
let running = false;
|
|
49
|
+
async function makeSureQueueIsStarted() {
|
|
50
|
+
if (running)
|
|
51
|
+
return;
|
|
52
|
+
running = true;
|
|
53
|
+
await runNext();
|
|
54
|
+
running = false;
|
|
55
|
+
}
|
|
56
|
+
async function runNext() {
|
|
57
|
+
const { p, f } = queue.shift();
|
|
58
|
+
try {
|
|
59
|
+
p.res(await f());
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
p.rej(error);
|
|
63
|
+
}
|
|
64
|
+
if (queue.length !== 0)
|
|
65
|
+
await runNext();
|
|
66
|
+
}
|
|
67
|
+
return (f) => {
|
|
68
|
+
const p = new ResablePromise();
|
|
69
|
+
queue.push({ f, p });
|
|
70
|
+
makeSureQueueIsStarted();
|
|
71
|
+
return p;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
46
74
|
class SyncPromise {
|
|
47
75
|
constructor(cb) {
|
|
48
76
|
this.thenListener = [];
|
|
@@ -284,4 +312,5 @@ exports.ResableSyncPromise = ResableSyncPromise;
|
|
|
284
312
|
exports.SettledPromise = SettledPromise;
|
|
285
313
|
exports.SettledSyncPromise = SettledSyncPromise;
|
|
286
314
|
exports.SyncPromise = SyncPromise;
|
|
315
|
+
exports.execQueue = execQueue;
|
|
287
316
|
exports.latestLatent = latestLatent;
|
|
@@ -3,6 +3,7 @@ type P<Args extends unknown[], Ret> = {
|
|
|
3
3
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): P<Args, Ret | TResult>;
|
|
4
4
|
} & ((...a: Args) => (CancelAblePromise<Ret> | Promise<Ret> | undefined));
|
|
5
5
|
export declare function latestLatent<Args extends unknown[], Ret>(cb: (...args: Args) => (CancelAblePromise<Ret> | Promise<Ret> | undefined)): P<Args, Ret>;
|
|
6
|
+
export declare function execQueue(): <T>(f: () => Promise<T>) => ResablePromise<void>;
|
|
6
7
|
export declare class SyncPromise<T = unknown> {
|
|
7
8
|
private thenListener;
|
|
8
9
|
private catchListener;
|
|
@@ -40,6 +40,34 @@ export function latestLatent(cb) {
|
|
|
40
40
|
propagateFuture(request, futures, "catch", prom);
|
|
41
41
|
return request;
|
|
42
42
|
}
|
|
43
|
+
export function execQueue() {
|
|
44
|
+
const queue = [];
|
|
45
|
+
let running = false;
|
|
46
|
+
async function makeSureQueueIsStarted() {
|
|
47
|
+
if (running)
|
|
48
|
+
return;
|
|
49
|
+
running = true;
|
|
50
|
+
await runNext();
|
|
51
|
+
running = false;
|
|
52
|
+
}
|
|
53
|
+
async function runNext() {
|
|
54
|
+
const { p, f } = queue.shift();
|
|
55
|
+
try {
|
|
56
|
+
p.res(await f());
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
p.rej(error);
|
|
60
|
+
}
|
|
61
|
+
if (queue.length !== 0)
|
|
62
|
+
await runNext();
|
|
63
|
+
}
|
|
64
|
+
return (f) => {
|
|
65
|
+
const p = new ResablePromise();
|
|
66
|
+
queue.push({ f, p });
|
|
67
|
+
makeSureQueueIsStarted();
|
|
68
|
+
return p;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
43
71
|
export class SyncPromise {
|
|
44
72
|
constructor(cb) {
|
|
45
73
|
this.thenListener = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "more-proms",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A collection of additional promise extending classes. Including a (from the outside) ResablePromise, CancelAblePromise and a latestLatent utility function.",
|
|
5
5
|
"main": "./app/dist/esm/moreProms.mjs",
|
|
6
6
|
"types": "./app/dist/esm/moreProms.d.ts",
|