@worker-tools/json-stream
Version:
Utilities for working with streaming JSON in Worker Runtimes such as Cloudflare Workers, Deno Deploy and Service Workers.
23 lines (22 loc) • 1.19 kB
TypeScript
declare type Awaitable<T> = T | PromiseLike<T>;
export declare type TaskState = 'idle' | 'pending' | 'fulfilled' | 'rejected';
export declare class TaskPromise<T, TT = T> implements Promise<T> {
#private;
static from<T>(task: () => Awaitable<T>): TaskPromise<T, T>;
private constructor();
get state(): TaskState;
/**
* Starts the execution of the task associated with this task promise.
* If you don't want to start the task at this moment, use `.map` instead.
*/
then<U = T, V = never>(onfulfilled?: ((value: T) => Awaitable<U>) | undefined | null, onrejected?: ((reason: any) => Awaitable<V>) | undefined | null): Promise<U | V>;
/**
* Applies transformations to the resolved value without triggering execution.
* Returns another task promise that triggers execution via `.then`
*/
map<U = T>(mapFn?: ((value: T, i?: 0, p?: TaskPromise<T, TT>) => Awaitable<U>) | undefined | null, thisArg?: any): TaskPromise<U, TT>;
catch<V = never>(onrejected?: ((reason: any) => Awaitable<V>) | null): Promise<T | V>;
finally(onfinally?: (() => void) | null): Promise<T>;
readonly [Symbol.toStringTag] = "TaskPromise";
}
export {};