Namespace webdriver.promise
code »Interfaces
|
Classes
|
Global Functions
Given an array of promises, will return a promise that will be fulfilled
with the fulfillment values of the input array's values. If any of the
input array's promises are rejected, the returned promise will be rejected
with the same reason.
Parameters |
---|
|
Returns |
|
code »webdriver.promise.asap ( value, callback, opt_errback )Invokes the appropriate callback function as soon as a promised
value
is resolved. This function is similar to
webdriver.promise.when
, except it does not return a new promise.
value
is resolved. This function is similar to
webdriver.promise.when
, except it does not return a new promise.code »webdriver.promise.checkedNodeCall ( fn, var_args ) ⇒ !webdriver.promise.Promise
Wraps a function that is assumed to be a node-style callback as its final
argument. This callback takes two arguments: an error value (which will be
null if the call succeeded), and the success value as the second argument.
If the call fails, the returned promise will be rejected, otherwise it will
be resolved with the result.
!webdriver.promise.Promise
Parameters |
---|
|
Returns |
|
code »webdriver.promise.consume ( generatorFn, opt_self, var_args ) ⇒ !webdriver.promise.Promise
Consumes a GeneratorFunction
. Each time the generator yields a
promise, this function will wait for it to be fulfilled before feeding the
fulfilled value back into next
. Likewise, if a yielded promise is
rejected, the rejection error will be passed to throw
.
Example 1: the Fibonacci Sequence.
webdriver.promise.consume(function* fibonacci() {
var n1 = 1, n2 = 1;
for (var i = 0; i < 4; ++i) {
var tmp = yield n1 + n2;
n1 = n2;
n2 = tmp;
}
return n1 + n2;
}).then(function(result) {
console.log(result); // 13
});
Example 2: a generator that throws.
webdriver.promise.consume(function* () {
yield webdriver.promise.delayed(250).then(function() {
throw Error('boom');
});
}).thenCatch(function(e) {
console.log(e.toString()); // Error: boom
});
!webdriver.promise.Promise
GeneratorFunction
. Each time the generator yields a
promise, this function will wait for it to be fulfilled before feeding the
fulfilled value back into next
. Likewise, if a yielded promise is
rejected, the rejection error will be passed to throw
.
webdriver.promise.consume(function* fibonacci() {
var n1 = 1, n2 = 1;
for (var i = 0; i < 4; ++i) {
var tmp = yield n1 + n2;
n1 = n2;
n2 = tmp;
}
return n1 + n2;
}).then(function(result) {
console.log(result); // 13
});
webdriver.promise.consume(function* () {
yield webdriver.promise.delayed(250).then(function() {
throw Error('boom');
});
}).thenCatch(function(e) {
console.log(e.toString()); // Error: boom
});
Parameters |
---|
Returns |
|
Throws |
|
Returns |
---|
|
code »webdriver.promise.createFlow ( callback ) ⇒ !webdriver.promise.Promise
Creates a new control flow. The provided callback will be invoked as the
first task within the new flow, with the flow as its sole argument. Returns
a promise that resolves to the callback result.
!webdriver.promise.Promise
Parameters |
---|
|
Returns |
|
Creates a new deferred object.
Returns |
---|
|
Creates a promise that will be resolved at a set time in the future.
Parameters |
---|
|
Returns |
|
Calls a function for each element in an array, and if the function returns
true adds the element to a new array.
If the return value of the filter function is a promise, this function
will wait for it to be fulfilled before determining whether to insert the
element into the new array.
If the filter function throws or returns a rejected promise, the promise
returned by this function will be rejected with the same reason. Only the
first failure will be reported; all subsequent errors will be silently
ignored.
Parameters |
---|
|
Creates a promise that has been resolved with the given value.
Parameters |
---|
|
Returns |
|
Parameters |
---|
|
Returns |
|
Returns a promise that will be resolved with the input value in a
fully-resolved state. If the value is an array, each element will be fully
resolved. Likewise, if the value is an object, all keys will be fully
resolved. In both cases, all nested arrays and objects will also be
fully resolved. All fields are resolved in place; the returned promise will
resolve on value
and not a copy.
Warning: This function makes no checks against objects that contain
cyclical references:
var value = {};
value['self'] = value;
webdriver.promise.fullyResolved(value); // Stack overflow.
value
and not a copy.
Warning: This function makes no checks against objects that contain
cyclical references:
var value = {};
value['self'] = value;
webdriver.promise.fullyResolved(value); // Stack overflow.
Parameters |
---|
|
Returns |
|
code »webdriver.promise.isError_ ( value ) ⇒ boolean
Tests if a value is an Error-like object. This is more than an straight
instanceof check since the value may originate from another context.
boolean
Parameters |
---|
|
Returns |
|
Tests is a function is a generator.
Parameters |
---|
|
Returns |
|
code »webdriver.promise.isPromise ( value ) ⇒ boolean
Determines whether a value
should be treated as a promise.
Any object whose "then" property is a function will be considered a promise.
boolean
value
should be treated as a promise.
Any object whose "then" property is a function will be considered a promise.Parameters |
---|
|
Returns |
|
Calls a function for each element in an array and inserts the result into a
new array, which is used as the fulfillment value of the promise returned
by this function.
If the return value of the mapping function is a promise, this function
will wait for it to be fulfilled before inserting it into the new array.
If the mapping function throws or returns a rejected promise, the
promise returned by this function will be rejected with the same reason.
Only the first failure will be reported; all subsequent errors will be
silently ignored.
Parameters |
---|
|
code »webdriver.promise.pushFlow_ ( flow )
Parameters |
---|
|
Creates a promise that has been rejected with the given reason.
Parameters |
---|
|
Returns |
|
Changes the default flow to use when no others are active.
Parameters |
---|
|
Throws |
|
code »webdriver.promise.when ( value, opt_callback, opt_errback ) ⇒ !webdriver.promise.Promise
Registers an observer on a promised value
, returning a new promise
that will be resolved when the value is. If value
is not a promise,
then the return promise will be immediately resolved.
!webdriver.promise.Promise
value
, returning a new promise
that will be resolved when the value is. If value
is not a promise,
then the return promise will be immediately resolved.