React Executor - v0.0.28
    Preparing search index...

    Interface Executor<Value>

    Manages the async task execution process and provides ways to access execution results, abort or replace a task execution, and subscribe to execution state changes.

    interface Executor<Value = any> {
        annotations: Record<PropertyKey, any>;
        invalidatedAt: number;
        isActive: boolean;
        isFulfilled: boolean;
        isInvalidated: boolean;
        isPending: boolean;
        isRejected: boolean;
        isSettled: boolean;
        key: any;
        manager: ExecutorManager;
        promise: AbortablePromise<Value> | null;
        reason: any;
        settledAt: number;
        task: ExecutorTask<Value> | null;
        value: Value | undefined;
        version: number;
        abort(reason?: unknown): void;
        activate(): () => void;
        annotate(patch: Record<PropertyKey, any>): void;
        clear(): void;
        execute(
            task: ExecutorTask<Value> | ExecutorTaskCallback<Value>,
        ): AbortablePromise<Value>;
        get(): Value;
        getOrAwait(): AbortablePromise<Value>;
        getOrDefault(): Value | undefined;
        getOrDefault<DefaultValue>(
            defaultValue: DefaultValue,
        ): Value | DefaultValue;
        getStateSnapshot(): ExecutorState<Value>;
        invalidate(invalidatedAt?: number): void;
        publish(event: PartialExecutorEvent): void;
        reject(reason: any, settledAt?: number): void;
        resolve(value: Value | PromiseLike<Value>, settledAt?: number): void;
        retry(): void;
        subscribe(listener: (value: ExecutorEvent) => void): () => void;
    }

    Type Parameters

    • Value = any

      The value stored by the executor.

    Hierarchy (View Summary)

    Index

    Properties

    annotations: Record<PropertyKey, any>

    The map of annotations associated with the executor.

    invalidatedAt: number

    The timestamp when the executor was invalidated, or 0 if the executor isn't invalidated.

    isActive: boolean

    true if the executor was activated more times than deactivated.

    isFulfilled: boolean

    true if the executor was fulfilled with a value, or false otherwise.

    isInvalidated: boolean

    true if invalidate was called on a settled executor and a new settlement hasn't occurred yet.

    isPending: boolean

    true if the execution is currently pending, or false otherwise.

    isRejected: boolean

    true if the executor was rejected with a reason, or false otherwise.

    isSettled: boolean

    true if the executor is fulfilled or rejected, or false otherwise.

    key: any

    The key of this executor, unique in scope of the manager.

    The manager that created the executor.

    promise: AbortablePromise<Value> | null

    The promise of the pending task execution, or null if there's no pending task execution.

    Note: This promise is aborted if the task is replaced. Use getOrAwait to wait until the executor becomes settled.

    reason: any

    The reason of the latest failure.

    Note: An executor may still have a rejection reason even if it was fulfilled. Check isRejected to ensure that an executor is actually rejected.

    settledAt: number

    The timestamp when the executor was settled, or 0 if it isn't settled.

    task: ExecutorTask<Value> | null

    The latest task that was executed, or null if the executor hasn't executed any tasks.

    Note: Unlike ReadonlyExecutor.task, this property is writable to allow plugins and advanced use cases to replace the stored task reference directly.

    value: Value | undefined

    The value of the latest fulfillment.

    Note: An executor may still have a value even if it was rejected. Use get, getOrDefault, or getOrAwait to retrieve the value of a fulfilled executor.

    version: number

    The integer version of the state of this executor that is incremented every time the executor is mutated.

    Methods

    • Instantly aborts pending execution and preserves available results as-is. The value (or error) returned from the pending task callback is ignored, and the signal passed to the task callback is aborted.

      Note: This method only affects the pending task promise, not the executor's settled state. To also clear or reject the executor's value, call clear or reject afterwards.

      Parameters

      • Optionalreason: unknown

        The abort reason used to reject the pending task promise.

      Returns void

    • Marks the executor as being actively monitored by an external consumer.

      An activated executor stays active until all returned deactivate callbacks are invoked.

      Returns () => void

      The callback that deactivates the executor if there are no more active consumers.

    • Merges the patch into the existing annotations.

      Parameters

      • patch: Record<PropertyKey, any>

        The patch containing new annotations.

      Returns void

    • Clears available results and doesn't affect the pending task execution.

      The latest task can still be retried after the executor is cleared.

      Returns void

    • If the executor is settled, marks the result as invalidated.

      Parameters

      • OptionalinvalidatedAt: number

        The timestamp to record as the invalidation time. Defaults to Date.now().

      Returns void

    • Instantly aborts pending execution and rejects the executor with the reason.

      Parameters

      • reason: any

        The reason of failure.

      • OptionalsettledAt: number

        The timestamp when the reason was acquired. Defaults to Date.now().

      Returns void

    • Aborts pending execution and fulfills the executor with the value.

      Note: If the value is a PromiseLike, it is wrapped internally and the task is updated to reflect the pending resolution. This differs from passing a plain value, where settlement is immediate.

      Parameters

      • value: Value | PromiseLike<Value>

        The value.

      • OptionalsettledAt: number

        The timestamp when the value was acquired. Ignored if value is a PromiseLike.

      Returns void

    • If the executor is not pending, the latest task is executed again. If there's no task then this is a no-op.

      Returns void

    • Subscribes the listener to changes of the observed value.

      Parameters

      • listener: (value: ExecutorEvent) => void

        The listener to subscribe.

      Returns () => void