more-proms 1.9.0 → 1.9.2
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.
|
@@ -4,10 +4,10 @@ type P<Args extends unknown[], Ret> = {
|
|
|
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
6
|
export declare function execQueue(defaultOptions?: {
|
|
7
|
-
skipAble?: boolean;
|
|
7
|
+
skipAble?: boolean | (() => void);
|
|
8
8
|
cancelVal?: any;
|
|
9
9
|
continueOnError?: boolean;
|
|
10
|
-
}): <T, FR extends Promise<T> | CancelAblePromise<T, string, string | void | Promise<any>>>(f: () => FR, options?: typeof defaultOptions | boolean, cancelPrevIfPossible?: boolean) => FR;
|
|
10
|
+
}): <T, FR extends Promise<T> | CancelAblePromise<T, string, string | void | Promise<any>>>(f: () => FR, options?: typeof defaultOptions | boolean | (() => void), cancelPrevIfPossible?: boolean) => FR;
|
|
11
11
|
export declare class SyncPromise<T = unknown> {
|
|
12
12
|
private thenListener;
|
|
13
13
|
private catchListener;
|
|
@@ -58,7 +58,7 @@ export type ResablePromise<T = unknown> = SettledPromProps<T> & ResablePromProps
|
|
|
58
58
|
} & Promise<T>;
|
|
59
59
|
export declare const CancelAblePromise: PromiseConstructor & (new <T = void, C = void, CT = C>(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void) => CancelAblePromise<T, C, CT>);
|
|
60
60
|
export type CancelAblePromise<T = unknown, C = void, CT = C> = SettledPromProps<T> & ResablePromProps<T> & CancelAblePromProps<T, C, CT> & {
|
|
61
|
-
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
61
|
+
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancelForward?: true): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
62
62
|
then<TResult1 = T, TResult2 = never, newC = void, newCT = newC>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancel?: (reason: newC) => newCT): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
63
63
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): CancelAblePromise<T | TResult>;
|
|
64
64
|
finally(onfinally?: (() => void) | undefined | null): CancelAblePromise<T>;
|
|
@@ -77,7 +77,7 @@ export type ResableSyncPromise<T = unknown> = SettledPromProps<T> & ResablePromP
|
|
|
77
77
|
} & SyncPromise<T>;
|
|
78
78
|
export declare const CancelAbleSyncPromise: typeof SyncPromise & (new <T = unknown, C = void, CT = C>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void) => CancelAbleSyncPromise<T, C, CT>);
|
|
79
79
|
export type CancelAbleSyncPromise<T = unknown, C = void, CT = C> = SettledPromProps<T> & ResablePromProps<T> & CancelAblePromProps<T, C, CT> & {
|
|
80
|
-
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
80
|
+
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancelForward?: true): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
81
81
|
then<TResult1 = T, TResult2 = never, newC = void, newCT = newC>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancel?: (reason: newC) => newCT): CancelAbleSyncPromise<TResult1 | TResult2, newC, newCT>;
|
|
82
82
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): CancelAbleSyncPromise<T | TResult>;
|
|
83
83
|
finally(onfinally?: (() => void) | undefined | null): CancelAbleSyncPromise<T>;
|
|
@@ -65,7 +65,11 @@ function execQueue(defaultOptions = {
|
|
|
65
65
|
if (wantToCancelUntil === ob)
|
|
66
66
|
wantToCancelUntil = undefined;
|
|
67
67
|
const wantToCancelThis = wantToCancelUntil !== undefined;
|
|
68
|
-
if (
|
|
68
|
+
if (wantToCancelThis && skipAble) {
|
|
69
|
+
if (skipAble instanceof Function)
|
|
70
|
+
skipAble();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
69
73
|
const prom = curFP = f();
|
|
70
74
|
curCancelVal = cancelVal;
|
|
71
75
|
const localPromsToContinue = [];
|
|
@@ -88,7 +92,7 @@ function execQueue(defaultOptions = {
|
|
|
88
92
|
running = false;
|
|
89
93
|
}
|
|
90
94
|
return (f, options = defaultOptions, cancelPrevIfPossible = false) => {
|
|
91
|
-
options = typeof options
|
|
95
|
+
options = typeof options !== "object" ? { ...defaultOptions, ...{ skipAble: options } } : { ...defaultOptions, ...options };
|
|
92
96
|
const p = new CancelAblePromise(() => { }, (cVal) => {
|
|
93
97
|
// on cancel
|
|
94
98
|
if (cancelDataStore !== undefined)
|
|
@@ -289,14 +293,15 @@ function mkExt(Prom) {
|
|
|
289
293
|
if (this.settled)
|
|
290
294
|
return;
|
|
291
295
|
this.cancelReason = reason;
|
|
292
|
-
for (const f of this.nestedCancels)
|
|
293
|
-
f(reason);
|
|
294
296
|
this.res = () => { };
|
|
295
297
|
this.rej = () => { };
|
|
296
298
|
this.cancelled = true;
|
|
297
299
|
const cancelResult = this.cancelFunc !== undefined ? this.cancelFunc(reason) : undefined;
|
|
298
300
|
this.onCancel.res({ reason, cancelResult });
|
|
299
301
|
return cancelResult;
|
|
302
|
+
}, (reason) => {
|
|
303
|
+
for (const f of this.nestedCancels)
|
|
304
|
+
f(reason);
|
|
300
305
|
});
|
|
301
306
|
}
|
|
302
307
|
then(onfulfilled, onrejected, onCancel) {
|
|
@@ -4,10 +4,10 @@ type P<Args extends unknown[], Ret> = {
|
|
|
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
6
|
export declare function execQueue(defaultOptions?: {
|
|
7
|
-
skipAble?: boolean;
|
|
7
|
+
skipAble?: boolean | (() => void);
|
|
8
8
|
cancelVal?: any;
|
|
9
9
|
continueOnError?: boolean;
|
|
10
|
-
}): <T, FR extends Promise<T> | CancelAblePromise<T, string, string | void | Promise<any>>>(f: () => FR, options?: typeof defaultOptions | boolean, cancelPrevIfPossible?: boolean) => FR;
|
|
10
|
+
}): <T, FR extends Promise<T> | CancelAblePromise<T, string, string | void | Promise<any>>>(f: () => FR, options?: typeof defaultOptions | boolean | (() => void), cancelPrevIfPossible?: boolean) => FR;
|
|
11
11
|
export declare class SyncPromise<T = unknown> {
|
|
12
12
|
private thenListener;
|
|
13
13
|
private catchListener;
|
|
@@ -58,7 +58,7 @@ export type ResablePromise<T = unknown> = SettledPromProps<T> & ResablePromProps
|
|
|
58
58
|
} & Promise<T>;
|
|
59
59
|
export declare const CancelAblePromise: PromiseConstructor & (new <T = void, C = void, CT = C>(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void) => CancelAblePromise<T, C, CT>);
|
|
60
60
|
export type CancelAblePromise<T = unknown, C = void, CT = C> = SettledPromProps<T> & ResablePromProps<T> & CancelAblePromProps<T, C, CT> & {
|
|
61
|
-
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
61
|
+
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancelForward?: true): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
62
62
|
then<TResult1 = T, TResult2 = never, newC = void, newCT = newC>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancel?: (reason: newC) => newCT): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
63
63
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): CancelAblePromise<T | TResult>;
|
|
64
64
|
finally(onfinally?: (() => void) | undefined | null): CancelAblePromise<T>;
|
|
@@ -77,7 +77,7 @@ export type ResableSyncPromise<T = unknown> = SettledPromProps<T> & ResablePromP
|
|
|
77
77
|
} & SyncPromise<T>;
|
|
78
78
|
export declare const CancelAbleSyncPromise: typeof SyncPromise & (new <T = unknown, C = void, CT = C>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void) => CancelAbleSyncPromise<T, C, CT>);
|
|
79
79
|
export type CancelAbleSyncPromise<T = unknown, C = void, CT = C> = SettledPromProps<T> & ResablePromProps<T> & CancelAblePromProps<T, C, CT> & {
|
|
80
|
-
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
80
|
+
then<TResult1 = T, TResult2 = never, newC extends C = C, newCT extends CT = CT>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancelForward?: true): CancelAblePromise<TResult1 | TResult2, newC, newCT>;
|
|
81
81
|
then<TResult1 = T, TResult2 = never, newC = void, newCT = newC>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, onCancel?: (reason: newC) => newCT): CancelAbleSyncPromise<TResult1 | TResult2, newC, newCT>;
|
|
82
82
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): CancelAbleSyncPromise<T | TResult>;
|
|
83
83
|
finally(onfinally?: (() => void) | undefined | null): CancelAbleSyncPromise<T>;
|
|
@@ -62,7 +62,11 @@ export function execQueue(defaultOptions = {
|
|
|
62
62
|
if (wantToCancelUntil === ob)
|
|
63
63
|
wantToCancelUntil = undefined;
|
|
64
64
|
const wantToCancelThis = wantToCancelUntil !== undefined;
|
|
65
|
-
if (
|
|
65
|
+
if (wantToCancelThis && skipAble) {
|
|
66
|
+
if (skipAble instanceof Function)
|
|
67
|
+
skipAble();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
66
70
|
const prom = curFP = f();
|
|
67
71
|
curCancelVal = cancelVal;
|
|
68
72
|
const localPromsToContinue = [];
|
|
@@ -85,7 +89,7 @@ export function execQueue(defaultOptions = {
|
|
|
85
89
|
running = false;
|
|
86
90
|
}
|
|
87
91
|
return (f, options = defaultOptions, cancelPrevIfPossible = false) => {
|
|
88
|
-
options = typeof options
|
|
92
|
+
options = typeof options !== "object" ? { ...defaultOptions, ...{ skipAble: options } } : { ...defaultOptions, ...options };
|
|
89
93
|
const p = new CancelAblePromise(() => { }, (cVal) => {
|
|
90
94
|
// on cancel
|
|
91
95
|
if (cancelDataStore !== undefined)
|
|
@@ -287,14 +291,15 @@ function mkExt(Prom) {
|
|
|
287
291
|
if (this.settled)
|
|
288
292
|
return;
|
|
289
293
|
this.cancelReason = reason;
|
|
290
|
-
for (const f of this.nestedCancels)
|
|
291
|
-
f(reason);
|
|
292
294
|
this.res = () => { };
|
|
293
295
|
this.rej = () => { };
|
|
294
296
|
this.cancelled = true;
|
|
295
297
|
const cancelResult = this.cancelFunc !== undefined ? this.cancelFunc(reason) : undefined;
|
|
296
298
|
this.onCancel.res({ reason, cancelResult });
|
|
297
299
|
return cancelResult;
|
|
300
|
+
}, (reason) => {
|
|
301
|
+
for (const f of this.nestedCancels)
|
|
302
|
+
f(reason);
|
|
298
303
|
});
|
|
299
304
|
}
|
|
300
305
|
then(onfulfilled, onrejected, onCancel) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "more-proms",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
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",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"colorful-cli-logger": "^1.0.0",
|
|
78
78
|
"commander": "^10.0.1",
|
|
79
|
-
"key-index": "^1.
|
|
79
|
+
"key-index": "^1.7.0",
|
|
80
80
|
"req-package-json": "^2.1.2"
|
|
81
81
|
}
|
|
82
82
|
}
|