more-proms 1.4.0 → 1.5.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.
@@ -13,15 +13,15 @@ export declare class ResablePromise<T = void> extends SettledPromise<T> {
13
13
  readonly rej: (err: any) => void;
14
14
  constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
15
15
  }
16
- export declare class CancelAblePromise<T = unknown, C = unknown> extends SettledPromise<T> {
16
+ export declare class CancelAblePromise<T = unknown, C = void> extends SettledPromise<T> {
17
17
  cancelled: boolean;
18
- cancel: () => C;
19
- onCancel: Promise<void>;
18
+ cancel: (reason: C) => void;
19
+ onCancel: Promise<C>;
20
20
  private nestedCancels;
21
- constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: () => C);
21
+ constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void);
22
22
  then<TResult1 = T, TResult2 = never>(onfulfilled: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): CancelAblePromise<TResult1 | TResult2>;
23
23
  catch<TResult = never>(onrejected: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): CancelAblePromise<T | TResult>;
24
- static all(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], unknown[]>;
25
- static race(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], unknown[]>;
24
+ static all(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], void>;
25
+ static race(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], void>;
26
26
  }
27
27
  export {};
@@ -99,15 +99,15 @@ class CancelAblePromise extends SettledPromise {
99
99
  this.cancelled = false;
100
100
  this.onCancel = new ResablePromise(() => { });
101
101
  this.nestedCancels = [];
102
- this.cancel = keyIndex.memoize(() => {
102
+ this.cancel = keyIndex.memoize((reason) => {
103
103
  for (const f of this.nestedCancels)
104
104
  f();
105
105
  if (this.settled)
106
106
  return;
107
107
  this.cancelled = true;
108
- this.onCancel.res();
108
+ this.onCancel.res(reason);
109
109
  if (cancel !== undefined)
110
- return cancel();
110
+ cancel(reason);
111
111
  });
112
112
  }
113
113
  then(onfulfilled, onrejected) {
@@ -130,18 +130,18 @@ class CancelAblePromise extends SettledPromise {
130
130
  function allOrRace(allOrRace, proms, ifOneChildCancels = "ignore") {
131
131
  const newP = new CancelAblePromise((res, rej) => {
132
132
  Promise[allOrRace](proms).then(res, rej);
133
- }, () => {
134
- return proms.map((p) => p.cancel());
133
+ }, (reason) => {
134
+ return proms.map((p) => p.cancel(reason));
135
135
  });
136
136
  if (ifOneChildCancels === "ignore")
137
- Promise.all(proms.map((p) => p.cancelled)).then(newP.cancel);
137
+ Promise.all(proms.map((p) => p.onCancel)).then((r) => { newP.cancel(r[0]); });
138
138
  else if (ifOneChildCancels === "cancelThis")
139
- Promise.race(proms.map((p) => p.cancelled)).then(newP.cancel);
139
+ Promise.race(proms.map((p) => p.onCancel)).then(newP.cancel);
140
140
  else if (ifOneChildCancels === "cancelAll")
141
- Promise.all(proms.map((p) => p.cancelled)).then(() => {
141
+ Promise.race(proms.map((p) => p.onCancel)).then((e) => {
142
142
  for (const prom of proms)
143
- prom.cancel();
144
- newP.cancel();
143
+ prom.cancel(e);
144
+ newP.cancel(e);
145
145
  });
146
146
  return newP;
147
147
  }
@@ -13,15 +13,15 @@ export declare class ResablePromise<T = void> extends SettledPromise<T> {
13
13
  readonly rej: (err: any) => void;
14
14
  constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
15
15
  }
16
- export declare class CancelAblePromise<T = unknown, C = unknown> extends SettledPromise<T> {
16
+ export declare class CancelAblePromise<T = unknown, C = void> extends SettledPromise<T> {
17
17
  cancelled: boolean;
18
- cancel: () => C;
19
- onCancel: Promise<void>;
18
+ cancel: (reason: C) => void;
19
+ onCancel: Promise<C>;
20
20
  private nestedCancels;
21
- constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: () => C);
21
+ constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancel?: (reason: C) => void);
22
22
  then<TResult1 = T, TResult2 = never>(onfulfilled: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): CancelAblePromise<TResult1 | TResult2>;
23
23
  catch<TResult = never>(onrejected: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): CancelAblePromise<T | TResult>;
24
- static all(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], unknown[]>;
25
- static race(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], unknown[]>;
24
+ static all(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], void>;
25
+ static race(proms: CancelAblePromise[], ifOneChildCancels?: "ignore" | "cancelThis" | "cancelAll"): CancelAblePromise<unknown[], void>;
26
26
  }
27
27
  export {};
@@ -96,15 +96,15 @@ export class CancelAblePromise extends SettledPromise {
96
96
  this.cancelled = false;
97
97
  this.onCancel = new ResablePromise(() => { });
98
98
  this.nestedCancels = [];
99
- this.cancel = memoize(() => {
99
+ this.cancel = memoize((reason) => {
100
100
  for (const f of this.nestedCancels)
101
101
  f();
102
102
  if (this.settled)
103
103
  return;
104
104
  this.cancelled = true;
105
- this.onCancel.res();
105
+ this.onCancel.res(reason);
106
106
  if (cancel !== undefined)
107
- return cancel();
107
+ cancel(reason);
108
108
  });
109
109
  }
110
110
  then(onfulfilled, onrejected) {
@@ -127,18 +127,18 @@ export class CancelAblePromise extends SettledPromise {
127
127
  function allOrRace(allOrRace, proms, ifOneChildCancels = "ignore") {
128
128
  const newP = new CancelAblePromise((res, rej) => {
129
129
  Promise[allOrRace](proms).then(res, rej);
130
- }, () => {
131
- return proms.map((p) => p.cancel());
130
+ }, (reason) => {
131
+ return proms.map((p) => p.cancel(reason));
132
132
  });
133
133
  if (ifOneChildCancels === "ignore")
134
- Promise.all(proms.map((p) => p.cancelled)).then(newP.cancel);
134
+ Promise.all(proms.map((p) => p.onCancel)).then((r) => { newP.cancel(r[0]); });
135
135
  else if (ifOneChildCancels === "cancelThis")
136
- Promise.race(proms.map((p) => p.cancelled)).then(newP.cancel);
136
+ Promise.race(proms.map((p) => p.onCancel)).then(newP.cancel);
137
137
  else if (ifOneChildCancels === "cancelAll")
138
- Promise.all(proms.map((p) => p.cancelled)).then(() => {
138
+ Promise.race(proms.map((p) => p.onCancel)).then((e) => {
139
139
  for (const prom of proms)
140
- prom.cancel();
141
- newP.cancel();
140
+ prom.cancel(e);
141
+ newP.cancel(e);
142
142
  });
143
143
  return newP;
144
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "more-proms",
3
- "version": "1.4.0",
3
+ "version": "1.5.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",