-
Notifications
You must be signed in to change notification settings - Fork 24
Async Library
The Async object contains the following functions.
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(): bool
Runs some tasks. Returns false
if all tasks are completed.
runToCompletion()
Runs tasks until all are completed.
The Task object contains the following functions.
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(...tasks: object): object
Returns a task that will complete after all of tasks
have completed.
whenAny(...tasks: object): object
Returns a task that will complete when at least one of tasks
has completed.
TaskCompletionSource(): object
Creates a new TaskCompletionSource.
getTask(): object
Returns a task that will complete when setResult
is called.
setCanceled()
setException(message: string)
setResult(result: any)
Sets the result value for the task returned by getTask
.
CancellationTokenSource(): object
Creates a new CancellationTokenSource.
isCancellationRequested(): bool
Returns true if cancellation was requested.
getToken(): object
Returns a CancellationToken for this instance.
cancel()
Signal all CancellationTokens returned from getToken
to cancel.
cancelAfter(seconds: double)
Calls cancel
after seconds
seconds.
CancellationToken(canceled: bool): object
Creates a new CancellationToken.
isCancellationRequested(): bool
Returns true if cancellation was requested.
register(action: function)
Registers a function to be called when cancellation is requested.
throwIfCancellationRequested()
Throws an exception if cancellation was requested.