Class: shaka.util.Task

Constructor

new Task()

A utility to create abortable, multi-stage tasks based on Promises.
Source:

Members

(private) abortedPromise_ :shaka.util.PublicPromise

Type:
Source:

(private, nullable) aborter_ :?function()

Type:
  • ?function()
Source:

(private, non-null) stages_ :Array.<shaka.util.Task.StageFunction>

Type:
Source:

(private) started_ :boolean

Type:
  • boolean
Source:

(private, non-null) taskPromise_ :shaka.util.PublicPromise

Type:
Source:

Methods

abort() → (non-null) {Promise}

Abort the task and run all 'catch' handlers. The caught error will have type 'aborted'.
Source:
Returns:
resolved once the task is aborted.
Type
Promise

append(fn)

Adds a new stage to the task. Should only be used before starting the task. A stage function should return either nothing or an Array with two items in it. If the stage function returns nothing, this stage is always successful and completes right away. No data will be passed to the next stage. If the stage function returns an Array, the first item should be a Promise which is resolved or rejected when the stage completes. If this promise is rejected, the task has failed and the task's 'catch' functions are called. The second item in the Array should be a function which aborts this stage of the operation. If this is omitted, then the stage cannot be terminated early, and aborting the Task during this stage means waiting for the end of the stage.
Parameters:
Name Type Description
fn shaka.util.Task.StageFunction The next stage of the task.
Source:
Throws:
if the task has been started.
Type
Error

(private) completeAbort_()

Rejects the task promise and then resolves the abort promise.
Source:

end()

End the running task. No more stages will be executed, and this will not be considered an error. Should always be called from within a stage.
Source:

getPromise() → (non-null) {Promise}

Get a promise which represents the entire task.
Source:
Returns:
Type
Promise

start()

Starts the task.
Source:
Throws:
if the task has already been started.
Type
Error

(private) startNextStage_(arg)

Start the next stage of the task.
Parameters:
Name Type Description
arg ? passed to the next stage.
Source:

Type Definitions

StageFunction

Type:
  • function(?): (Array|undefined)
Source: