@terrygonguet/utils 0.13.1 → 0.13.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.
- package/dist/task.d.mts +1 -0
- package/dist/task.mjs +5 -0
- package/package.json +1 -1
package/dist/task.d.mts
CHANGED
|
@@ -31,6 +31,7 @@ declare class Task<T, E extends Error = Error> {
|
|
|
31
31
|
recover<E2 extends E>(onFailed: (error: E) => Task<T, E2>): Task<T, E2>;
|
|
32
32
|
flatten(): T extends Task<infer U> ? Task<U> : Task<T>;
|
|
33
33
|
orDefault(defaultValue: T): Promise<T>;
|
|
34
|
+
asTuple(): Promise<[E, null] | [null, T]>;
|
|
34
35
|
unwrap(): T;
|
|
35
36
|
toString(): string;
|
|
36
37
|
}
|
package/dist/task.mjs
CHANGED
|
@@ -171,6 +171,11 @@ var Task = class Task {
|
|
|
171
171
|
else return defaultValue;
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
+
async asTuple() {
|
|
175
|
+
if (this._state.type == "pending") return this._state.promise.then(() => this.asTuple());
|
|
176
|
+
else if (this._state.type == "complete") return [null, this._state.value];
|
|
177
|
+
else return [this._state.error, null];
|
|
178
|
+
}
|
|
174
179
|
unwrap() {
|
|
175
180
|
if (this._state.type == "complete") return this._state.value;
|
|
176
181
|
else if (this._state.type == "failed") throw new Error("Tried to unwrap a failed Task");
|