@ng-web-apis/workers
Version:
A library for comfortable use of Web Workers API in Angular
15 lines (14 loc) • 684 B
TypeScript
import { Observable } from 'rxjs';
import type { TypedMessageEvent } from '../types/typed-message-event';
import type { WorkerFunction } from '../types/worker-function';
export declare class WebWorker<T = any, R = any> extends Observable<TypedMessageEvent<R>> {
private readonly worker;
private readonly url;
private readonly destroy$;
constructor(url: string, options?: WorkerOptions);
static fromFunction<T, R>(fn: WorkerFunction<T, R>, options?: WorkerOptions): WebWorker<T, R>;
static execute<T, R>(fn: WorkerFunction<T, R>, data: T): Promise<TypedMessageEvent<R>>;
private static createFnUrl;
terminate(): void;
postMessage(value: T): void;
}