Skip to content

Latest commit

 

History

History
162 lines (134 loc) · 5.86 KB

scheduling.md

File metadata and controls

162 lines (134 loc) · 5.86 KB

Scheduling

Back to Index

Table of Contents

Class: AsyncQueue

An asynchronous queue.

Syntax

export declare class AsyncQueue<T> {
    constructor(iterable?: Iterable<T | PromiseLike<T>>);
    put(value: T | PromiseLike<T>): void;
    get(): Promise<T>;
}

new AsyncQueue(iterable?)

Initializes a new instance of the AsyncQueue class.

  • iterable <Iterable> An optional iterable of values or promises.

queue.size

Gets the number of entries in the queue. When positive, indicates the number of entries available to get. When negative, indicates the number of requests waiting to be fulfilled.

queue.put(value)

Adds a value to the end of the queue. If the queue is empty but has a pending dequeue request, the value will be dequeued and the request fulfilled.

  • value <any> A value or promise to add to the queue.

queue.get()

Removes and returns a Promise for the first value in the queue. If the queue is empty, returns a Promise for the next value to be added to the queue.

Class: AsyncBoundedQueue

An asynchronous queue with a bounded endpoint.

Syntax

export declare class AsyncBoundedQueue<T> {
    constructor(iterable?: Iterable<T | PromiseLike<T>>);
    put(value: T | PromiseLike<T>): void;
    end(): void;
    get(): Promise<T | undefined>;
    drain(): AsyncIterableIterator<T>;
}

new AsyncBoundedQueue(iterable?)

Initializes a new instance of the AsyncBoundedQueue class.

  • iterable <Iterable> An optional iterable of values or promises.

queue.size

Gets the number of entries in the queue. When positive, indicates the number of entries available to get. When negative, indicates the number of requests waiting to be fulfilled.

queue.put(value)

Adds a value to the end of the queue. If the queue is empty but has a pending dequeue request, the value will be dequeued and the request fulfilled.

  • value <any> A value or promise to add to the queue.

queue.end()

Indicates the queue is done adding and that no more items will be added to the queue.

queue.get()

Removes and returns a Promise for the first value in the queue. If the queue has ended, returns a Promise for undefined. If the queue is empty, returns a Promise for the next value to be added to the queue.

queue.drain()

Consumes all items in the queue until the queue ends.

Class: AsyncStack

An asynchronous stack.

Syntax

export declare class AsyncStack<T> {
    constructor(iterable?: Iterable<T | PromiseLike<T>>);
    push(value: T | PromiseLike<T>): void;
    pop(): Promise<T>;
}

new AsyncStack(iterable?)

Initializes a new instance of the AsyncStack class.

  • iterable <Iterable> An optional iterable of values or promises.

stack.size

Gets the number of entries in the stack. When positive, indicates the number of entries available to get. When negative, indicates the number of requests waiting to be fulfilled.

stack.push(value)

Adds a value to the top of the stack. If the stack is empty but has a pending pop request, the value will be popped and the request fulfilled.

  • value <any> A value or promise to add to the stack.

stack.pop()

Removes and returns a Promise for the top value of the stack. If the stack is empty, returns a Promise for the next value to be pushed on to the stack.

Function: delay(msec, value?)

Waits the specified number of milliseconds before resolving with the provided value.

  • msec <Number> The number of milliseconds to delay.
  • value <any> The resolution value for the promise.
  • Returns: <Promise>

Syntax

export declare function delay(msec: number): Promise<void>;
export declare function delay<T>(msec: number, value?: T | PromiseLike<T>): Promise<T>;

Function: delay(token, msec, value?)

Waits the specified number of milliseconds before resolving with the provided value.

Syntax

export declare function delay(token: CancellationToken, msec: number): Promise<void>;
export declare function delay<T>(token: CancellationToken, msec: number, value?: T | PromiseLike<T>): Promise<T>;