Class: shaka.routing.Walker

Constructor

new Walker(startingAt, startingWith, implementation)

Create a new walker that starts at |startingAt| and with |startingWith|. The instance of |startingWith| will be the one that the walker holds and uses for its life. No one else should reference it. The per-instance behaviour for the walker is provided via |implementation| which is used to connect this walker with the "outside world".
Parameters:
Name Type Description
startingAt shaka.routing.Node
startingWith shaka.routing.Payload
implementation shaka.routing.Walker.Implementation
Implements:
Source:

Members

(private) currentlyAt_ :shaka.routing.Node

Type:
Source:

(private) isAlive_ :boolean

This flag is used by the main loop to know if it should keep doing work. It will be true from now until |destroy| is called.
Type:
  • boolean
Source:

(private, non-null) mainLoopPromise_ :Promise

Hold a reference to the main loop's promise so that we know when it has exited. This will determine when |destroy| can resolve. Purposely make the main loop start next interpreter cycle so that the constructor will finish before it starts.
Type:
  • Promise
Source:

(private, non-null) requests_ :Array.<shaka.routing.Walker.Request_>

Type:
Source:

(private) waitForWork_ :shaka.util.PublicPromise

When we run out of work to do, we will set this promise so that when new work is added (and this is not null) it can be resolved. The only time when this should be non-null is when we are waiting for more work.
Type:
Source:

Methods

(async, export) destroy() → (non-null) {Promise}

Request that this object be destroyed, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
Implements:
Source:
Returns:
Type
Promise

(private) doOneThing_() → (non-null) {Promise}

Do one thing to move the walker closer to its destination. This can be: 1. Starting a new route. 2. Taking one more step/finishing a route. 3. Wait for a new route.
Source:
Returns:
Type
Promise

getCurrentPayload() → {shaka.routing.Payload}

Get the current routing payload.
Source:
Returns:
Type
shaka.routing.Payload

(async, private) mainLoop_() → (non-null) {Promise}

Source:
Returns:
Type
Promise

startNewRoute(create) → {shaka.routing.Walker.Listeners}

Ask the walker to start a new route. When the walker is ready to start a new route, it will call |create| and |create| will provide the walker with a new route to execute. If any previous calls to |startNewRoute| created non-interruptible routes, |create| won't be called until all previous non-interruptible routes have finished. This method will return a collection of listeners that the caller can hook into. Any listener that the caller is interested should be assigned immediately after calling |startNewRoute| or else they could miss the event they want to listen for.
Parameters:
Name Type Description
create function(shaka.routing.Payload):?shaka.routing.Walker.Route
Source:
Returns:
Type
shaka.routing.Walker.Listeners

(async, private) takeNextStep_() → (non-null) {Promise}

Move forward one step on our current route. This assumes that we have a current route. A couple things can happen when moving forward: 1. An error - if an error occurs, it will signal an error occurred, attempt to recover, and drop the route. 2. Move - if no error occurs, we will move forward. When we arrive at our destination, it will signal the end and drop the route. In the event of an error or arriving at the destination, we drop the current route. This allows us to pick-up a new route next time the main loop iterates.
Source:
Returns:
Type
Promise

(private) tryNewRoute_() → {boolean}

Check if the walker can start a new route. There are a couple ways this can happen: 1. We have a new request but no current route 2. We have a new request and our current route can be interrupted
Source:
Returns:
|true| when a new route was started (regardless of reason) and |false| when no new route was started.
Type
boolean

(private) unblockMainLoop_()

If the main loop is blocked waiting for new work, then resolve the promise so that the next iteration of the main loop can execute.
Source:

Type Definitions

ActiveRoute_

The active route is the walker's internal representation of a route. It is the union of |shaka.routing.Walker.Request_| and the |shaka.routing.Walker.Route| created by |shaka.routing.Walker.Request_|.
Type:
Properties:
Name Type Description
node shaka.routing.Node The node that the walker should move towards. This will be passed to |shaka.routing.Walker.Implementation.getNext| to help determine where to go next.
{shaka.routing.Payload| payload The payload that the walker should have once it arrives at |node|. This will be passed to the |shaka.routing.Walker.Implementation.getNext| to help determine where to go next.
interruptible boolean Whether or not this route can be interrupted by another request. When |true| this route will be interrupted so that a pending request can be resolved. When |false|, the route will be allowed to finished before resolving the next request.
listeners shaka.routing.Walker.Listeners The listeners that the walker can used to communicate with whoever requested the route.
Source:

Implementation

There are some parts of the walker that will be per-instance. This type provides those per-instance parts.
Type:
Properties:
Name Type Description
{function( shaka.routing.Node, shaka.routing.Payload, shaka.routing.Node, shaka.routing.Payload):shaka.routing.Node getNext Get the next node that the walker should move to. This method will be passed (in this order) the current node, current payload, destination node, and destination payload.
enterNode function When the walker moves into a node, it will call |enterNode| and allow the implementation to change the current payload. This method will be passed (in this order) the node the walker is entering, the current payload, and the destination payload. This method should NOT modify the destination payload.
{function( shaka.routing.Payload, !Error):!Promise. handleError This is the callback for when |enterNode| fails. It is passed the current payload and the error. If a step is aborted, the error will be OPERATION_ABORTED. It should reset all external dependences, modify the payload, and return the new current node. Calls to |handleError| should always resolve and the walker should always be able to continue operating.
onIdle function This is the callback for when the walker has finished processing all route requests and needs to wait for more work. |onIdle| will be passed the current node. After |onIdle| has been called, the walker will block until a new request is made, or the walker is destroyed.
Source:

Listeners

The collection of callbacks that the walker will call while executing a route. By setting these immediately after calling |startNewRoute| the user can react to route-specific events.
Type:
  • {onStart: function(), onEnd: function(), onCancel: function(), onError: function(!Error), onSkip: function(), onEnter: function(shaka.routing.Node)}
Properties:
Name Type Description
onStart function The callback for when the walker has accepted the route and will soon take the first step unless interrupted. Either |onStart| or |onSkip| will be called.
onEnd function The callback for when the walker has reached the end of the route. For every route that had |onStart| called, either |onEnd|, |onCancel|, or |onError| will be called.
onCancel function The callback for when the walker is stopping a route before getting to the end. This will be called either when a new route is interrupting the route, or the walker is being destroyed mid-route. |onCancel| will only be called when a route has been interrupted by another route or the walker is being destroyed.
onError function The callback for when the walker failed to execute the route because an unexpected error occurred. The walker will enter a recovery mode and the route will be abandoned.
onSkip function The callback for when the walker was ready to start the route, but the create-method returned |null|.
onEnter function The callback for when the walker enters a node. This will allow us to track the progress of the walker within a per-route scope.
Source:

Request_

The request is how users can talk to the walker. They can give the walker a request and when the walker is ready, it will resolve the request by calling |create|.
Type:
Properties:
Name Type Description
create function The function called when the walker is ready to start a new route. This can return |null| to say that the request was not possible and should be skipped.
listeners shaka.routing.Walker.Listeners The collection of callbacks that the walker will use to talk to whoever provided the request.
Source:

Route

The public description of where the walker should go. This is created when the callback given to |startNewRoute| is called by the walker.
Type:
Properties:
Name Type Description
node shaka.routing.Node The node that the walker should move towards. This will be passed to |shaka.routing.Walker.Implementation.getNext| to help determine where to go next.
{shaka.routing.Payload| payload The payload that the walker should have once it arrives at |node|. This will be passed to the |shaka.routing.Walker.Implementation.getNext| to help determine where to go next.
interruptible boolean Whether or not this route can be interrupted by another request. When |true| this route will be interrupted so that a pending request can be resolved. When |false|, the route will be allowed to finished before resolving the next request.
Source: