Class webdriver.promise.ControlFlow
Extends
.
Defined in: promise.js.
Constructor Attributes | Constructor Name and Description |
---|---|
webdriver.promise.ControlFlow(opt_timer)
Handles the execution of scheduled tasks, each of which may be an
asynchronous operation.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
webdriver.promise.ControlFlow.defaultTimer
The default timer object, which uses the global timer functions.
|
<static> |
webdriver.promise.ControlFlow.EVENT_LOOP_FREQUENCY
How often, in milliseconds, the event loop should run.
|
<static> |
webdriver.promise.ControlFlow.EventType
Events that may be emitted by an webdriver.promise.ControlFlow.
|
The timer used by this instance.
|
Method Attributes | Method Name and Description |
---|---|
Appends a summary of this instance's recent task history to the given
error's stack trace.
|
|
await(promise)
Schedules a task that will wait for another promise to resolve.
|
|
Clears this instance's task history.
|
|
execute(fn, opt_description)
Schedules a task for execution.
|
|
Returns a summary of the recent task activity for this instance.
|
|
reset()
Resets this instance, clearing its queue and removing all event listeners.
|
|
timeout(ms, opt_description)
Inserts a {@code setTimeout} into the command queue.
|
|
wait(condition, timeout, opt_message)
Schedules a task that shall wait for a condition to hold.
|
Each task scheduled within this flow may return a webdriver.promise.Promise to indicate it is an asynchronous operation. The ControlFlow will wait for such promises to be resolved before marking the task as completed.
Tasks and each callback registered on a webdriver.promise.Deferred will be run in their own ControlFlow frame. Any tasks scheduled within a frame will have priority over previously scheduled tasks. Furthermore, if any of the tasks in the frame fails, the remainder of the tasks in that frame will be discarded and the failure will be propagated to the user through the callback/task's promised result.
Each time a ControlFlow empties its task queue, it will fire an webdriver.promise.ControlFlow.EventType.IDLE event. Conversely, whenever the flow terminates due to an unhandled error, it will remove all remaining tasks in its queue and fire an webdriver.promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION event. If there are no listeners registered with the flow, the error will be rethrown to the global error handler.
- Parameters:
- {webdriver.promise.ControlFlow.Timer=} opt_timer
- The timer object to use. Should only be set for testing.
- Parameters:
- {!(Error|goog.testing.JsUnitException)} e
- The error to annotate.
- Returns:
- {!(Error|goog.testing.JsUnitException)} The annotated error.
- Parameters:
- {!webdriver.promise.Promise} promise
- The promise to wait on.
- Returns:
- {!webdriver.promise.Promise} A promise that will resolve when the task has completed.
- Parameters:
- {!Function} fn
- The function to call to start the task. If the function returns a webdriver.promise.Promise, this instance will wait for it to be resolved before starting the next task.
- {string=} opt_description
- A description of the task.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the result of the action.
- Returns:
- {!Array.
} A summary of this instance's recent task activity.
- Returns:
- {string} The scheduled tasks still pending with this instance.
- Parameters:
- {number} ms
- The timeout delay, in milliseconds.
- {string=} opt_description
- A description to accompany the timeout.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the result of the action.
Condition functions may schedule sub-tasks with this instance, however, their execution time will be factored into whether a wait has timed out.
In the event a condition returns a Promise, the polling loop will wait for it to be resolved before evaluating whether the condition has been satisfied. The resolution time for a promise is factored into whether a wait has timed out.
If the condition function throws, or returns a rejected promise, the wait task will fail.
- Parameters:
- {!Function} condition
- The condition function to poll.
- {number} timeout
- How long to wait, in milliseconds, for the condition to hold before timing out.
- {string=} opt_message
- An optional error message to include if the wait times out; defaults to the empty string.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved when the condition has been satisified. The promise shall be rejected if the wait times out waiting for the condition.