@juulsgaard/signal-tools 18.0.3 → 18.0.4
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/index.d.ts
CHANGED
|
@@ -497,6 +497,7 @@ declare abstract class IRequestState implements Subscribable<unknown> {
|
|
|
497
497
|
* @param onError - Action to perform on error
|
|
498
498
|
*/
|
|
499
499
|
abstract then(onValue: (value: unknown) => void, onError?: (error: Error) => void): this;
|
|
500
|
+
asPromise(): Promise<unknown>;
|
|
500
501
|
/**
|
|
501
502
|
* Perform an action if the request fails
|
|
502
503
|
* @param onError
|
|
@@ -525,6 +526,7 @@ declare abstract class IValueRequestState<T> extends IRequestState implements Su
|
|
|
525
526
|
then(onValue: (value: T) => void, onError?: (error: Error) => void): this;
|
|
526
527
|
catch(onError: (error: Error) => void): this;
|
|
527
528
|
finally(onComplete: (error?: Error) => void): this;
|
|
529
|
+
asPromise(): Promise<T>;
|
|
528
530
|
/**
|
|
529
531
|
* Cancel a running request
|
|
530
532
|
* @param error - Optionally provide a custom error to throw when cancelling the request
|
|
@@ -2,6 +2,9 @@ import { first } from 'rxjs';
|
|
|
2
2
|
import { parseError } from '@juulsgaard/ts-tools';
|
|
3
3
|
|
|
4
4
|
class IRequestState {
|
|
5
|
+
asPromise() {
|
|
6
|
+
return new Promise((resolve, reject) => this.then(resolve, reject));
|
|
7
|
+
}
|
|
5
8
|
/**
|
|
6
9
|
* Subscribe to the underlying request Observable
|
|
7
10
|
* @param observer
|
|
@@ -34,6 +37,9 @@ class IValueRequestState extends IRequestState {
|
|
|
34
37
|
});
|
|
35
38
|
return this;
|
|
36
39
|
}
|
|
40
|
+
asPromise() {
|
|
41
|
+
return new Promise((resolve, reject) => this.then(resolve, reject));
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
export { IRequestState, IValueRequestState };
|
package/package.json
CHANGED