Skip to content

Async Library

Rohan Singh edited this page Feb 3, 2015 · 3 revisions

Exports

Async

The Async object contains the following functions.

start

start(enumerator: object): object

Starts running a task. Returns a task that completes when the started task completes.

start(action: function): object

Starts running a task. action should return an enumerator when called.

run

run(): bool

Runs some tasks. Returns false if all tasks are completed.

runToCompletion

runToCompletion()

Runs tasks until all are completed.

Task

The Task object contains the following functions.

delay

delay(seconds: number): object

Returns a task that will complete after seconds seconds.

delay(seconds: number, cancellationToken: object)

Returns a task that will complete after seconds seconds, or when cancellationToken is canceled.

whenAll

whenAll(...tasks: object): object

Returns a task that will complete after all of tasks have completed.

whenAny

whenAny(...tasks: object): object

Returns a task that will complete when at least one of tasks has completed.

TaskCompletionSource

TaskCompletionSource(): object

Creates a new TaskCompletionSource.

getTask

getTask(): object

Returns a task that will complete when setResult is called.

setCanceled

setCanceled()

setException

setException(message: string)

setResult

setResult(result: any)

Sets the result value for the task returned by getTask.

CancellationTokenSource

CancellationTokenSource(): object

Creates a new CancellationTokenSource.

isCancellationRequested

isCancellationRequested(): bool

Returns true if cancellation was requested.

getToken

getToken(): object

Returns a CancellationToken for this instance.

cancel

cancel()

Signal all CancellationTokens returned from getToken to cancel.

cancelAfter

cancelAfter(seconds: double)

Calls cancel after seconds seconds.

CancellationToken

CancellationToken(canceled: bool): object

Creates a new CancellationToken.

isCancellationRequested

isCancellationRequested(): bool

Returns true if cancellation was requested.

register

register(action: function)

Registers a function to be called when cancellation is requested.

throwIfCancellationRequested

throwIfCancellationRequested()

Throws an exception if cancellation was requested.

Clone this wiki locally