Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LroEngine<TResult, TState>

Package version

The LRO Engine, a class that performs polling.

Type parameters

Hierarchy

  • Poller<TState, TResult>
    • LroEngine

Implements

Index

Constructors

constructor

Properties

Protected operation

operation: PollOperation<TState, TResult>

The poller's operation is available in full to any of the methods of the Poller class and any class extending the Poller class.

Methods

cancelOperation

  • cancelOperation(options?: { abortSignal?: AbortSignalLike }): Promise<void>
  • Attempts to cancel the underlying operation.

    It only optionally receives an object with an abortSignal property, from @azure/abort-controller's AbortSignalLike.

    If it's called again before it finishes, it will throw an error.

    Parameters

    • Default value options: { abortSignal?: AbortSignalLike } = {}

      Optional properties passed to the operation's update method.

      • Optional abortSignal?: AbortSignalLike

    Returns Promise<void>

delay

  • delay(): Promise<void>

getOperationState

  • getOperationState(): TState
  • Returns the state of the operation.

    Even though TState will be the same type inside any of the methods of any extension of the Poller class, implementations of the pollers can customize what's shared with the public by writing their own version of the getOperationState method, and by defining two types, one representing the internal state of the poller and a public type representing a safe to share subset of the properties of the internal state. Their definition of getOperationState can then return their public type.

    Example:

    // Let's say we have our poller's operation state defined as:
    interface MyOperationState extends PollOperationState<ResultType> {
      privateProperty?: string;
      publicProperty?: string;
    }
    
    // To allow us to have a true separation of public and private state, we have to define another interface:
    interface PublicState extends PollOperationState<ResultType> {
      publicProperty?: string;
    }
    
    // Then, we define our Poller as follows:
    export class MyPoller extends Poller<MyOperationState, ResultType> {
      // ... More content is needed here ...
    
      public getOperationState(): PublicState {
        const state: PublicState = this.operation.state;
        return {
          // Properties from PollOperationState<TResult>
          isStarted: state.isStarted,
          isCompleted: state.isCompleted,
          isCancelled: state.isCancelled,
          error: state.error,
          result: state.result,
    
          // The only other property needed by PublicState.
          publicProperty: state.publicProperty
        }
      }
    }

    You can see this in the tests of this repository, go to the file: ../test/utils/testPoller.ts and look for the getOperationState implementation.

    Returns TState

getResult

  • getResult(): TResult | undefined
  • Returns the result value of the operation, regardless of the state of the poller. It can return undefined or an incomplete form of the final TResult value depending on the implementation.

    Returns TResult | undefined

isDone

  • isDone(): boolean

isStopped

  • isStopped(): boolean

onProgress

  • Invokes the provided callback after each polling is completed, sending the current state of the poller's operation.

    It returns a method that can be used to stop receiving updates on the given callback function.

    Parameters

    • callback: (state: TState) => void
        • (state: TState): void
        • Parameters

          • state: TState

          Returns void

    Returns CancelOnProgress

poll

  • poll(options?: { abortSignal?: AbortSignalLike }): Promise<void>
  • Returns a promise that will resolve once a single polling request finishes. It does this by calling the update method of the Poller's operation.

    It only optionally receives an object with an abortSignal property, from @azure/abort-controller's AbortSignalLike.

    Parameters

    • Default value options: { abortSignal?: AbortSignalLike } = {}

      Optional properties passed to the operation's update method.

      • Optional abortSignal?: AbortSignalLike

    Returns Promise<void>

pollUntilDone

  • pollUntilDone(): Promise<TResult>

stopPolling

  • stopPolling(): void

toString

  • toString(): string

Generated using TypeDoc