UNPKG

@orbit/core

Version:

Core library for Orbit - a flexible data access and synchronization layer.

50 lines (49 loc) 1.59 kB
import { Task, Performer } from './task'; /** * A `TaskProcessor` performs a `Task` by calling `perform()` on its target. * This is triggered by calling `process()` on the processor. * * A processor maintains a promise that represents the eventual state (resolved * or rejected) of the task. This promise is created upon construction, and * will be returned by calling `settle()`. * * A task can be re-tried by first calling `reset()` on the processor. This * will clear the processor's state and allow `process()` to be invoked again. */ export declare class TaskProcessor<Type = string, Data = unknown, Options = unknown, Result = unknown> { target: Performer<Type, Data, Options, Result>; task: Task<Type, Data, Options>; private _started; private _settled; private _settlement; private _success?; private _fail?; /** * Creates an instance of TaskProcessor. */ constructor(target: Performer<Type, Data, Options, Result>, task: Task<Type, Data, Options>); /** * Clears the processor state, allowing for a fresh call to `process()`. */ reset(): void; /** * Has `process` been invoked? */ get started(): boolean; /** * Has promise settled, either via `process` or `reject`? */ get settled(): boolean; /** * The eventual result of processing. */ settle(): Promise<Result>; /** * Invokes `perform` on the target. */ process(): Promise<Result>; /** * Reject the current promise with a specific error. */ reject(e: Error): void; }