selenium-webdriver
Version:
The official WebDriver JavaScript bindings from the Selenium project
84 lines (81 loc) • 9.55 kB
HTML
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"><meta http-equiv="Content-Language" content="en"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Deferred</title><link href="dossier.css" rel="stylesheet" type="text/css"><header><div><form><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></header><main><article><div class="parentlink"><b>Namespace:</b> <a href="namespace_webdriver_promise.html">webdriver.promise</a></div><div class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l676">View Source</a></div><h1>class Deferred<T></h1><dl><dt>All implemented interfaces<dd><code>IThenable<T></code><dd><code><a href="interface_webdriver_promise_Thenable.html">webdriver.promise.Thenable</a><T></code></dl><p>Represents a value that will be resolved at some point in the future. This
class represents the protected "producer" half of a Promise - each Deferred
has a <code>promise</code> property that may be returned to consumers for
registering callbacks, reserving the ability to resolve the deferred to the
producer.</p>
<p>If this Deferred is rejected and there are no listeners registered before
the next turn of the event loop, the rejection will be passed to the
<a href="class_webdriver_promise_ControlFlow.html"><code>webdriver.promise.ControlFlow</code></a> as an unhandled failure.</p>
<h3>new Deferred(<wbr>opt_flow)</h3><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_flow<code>?<a href="class_webdriver_promise_ControlFlow.html">webdriver.promise.ControlFlow</a>=</code><dd><p>The control flow
this instance was created under. This should only be provided during
unit tests.</p>
</dl></div></div><h2>Instance Methods</h2><div id="cancel" class="function"><div><h3>cancel(<wbr>opt_reason)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l722">code »</a></span></h3><p>Cancels the computation of this promise's value, rejecting the promise in the
process. This method is a no-op if the promise has already been resolved.</p>
<p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#cancel">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_reason<code>?(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|<a href="class_webdriver_promise_CancellationError.html">webdriver.promise.CancellationError</a>)=</code><dd><p>The reason this
promise is being cancelled.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="fulfill" class="function"><div><h3>fulfill(<wbr>opt_value)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l697">code »</a></span></h3><p>Resolves this deferred with the given value. It is safe to call this as a
normal function (with no bound "this").</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_value<code>?(T|{then: ?})=</code><dd><p>The fulfilled value.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="isPending" class="function"><div><h3>isPending()<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l716">code »</a></span></h3><p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#isPending">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd><p>Whether this promise's value is still being computed.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="reject" class="function"><div><h3>reject(<wbr>opt_reason)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l707">code »</a></span></h3><p>Rejects this promise with the given reason. It is safe to call this as a
normal function (with no bound "this").</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_reason<code>*=</code><dd><p>The rejection reason.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="then" class="function"><div><h3>then(<wbr>opt_callback, opt_errback)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l731">code »</a></span></h3><div class="tags"><span>deprecated</span></div><p>Registers listeners for when this instance is resolved.</p>
<p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#then">webdriver.promise.Thenable</a>, <a href="#then">IThenable</a></p><dl><dt>Deprecated<dd><p>Use <code>then</code> from the promise property directly.</p>
</dl><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_callback<code>?function(T): (R|IThenable<R>)=</code><dd><p>The
function to call if this promise is successfully resolved. The function
should expect a single argument: the promise's resolved value.</p>
<dt>opt_errback<code>?function(*): (R|IThenable<R>)=</code><dd><p>The function to call if this promise is rejected. The function should
expect a single argument: the rejection reason.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>A new promise which will be
resolved with the result of the invoked callback.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="thenCatch" class="function"><div><h3>thenCatch(<wbr>errback)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l740">code »</a></span></h3><div class="tags"><span>deprecated</span></div><p>Registers a listener for when this promise is rejected. This is synonymous
with the <code>catch</code> clause in a synchronous API:</p>
<pre><code>// Synchronous API:
try {
doSynchronousWork();
} catch (ex) {
console.error(ex);
}
// Asynchronous promise API:
doAsynchronousWork().thenCatch(function(ex) {
console.error(ex);
});
</code></pre>
<p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#thenCatch">webdriver.promise.Thenable</a></p><dl><dt>Deprecated<dd><p>Use <code>thenCatch</code> from the promise property directly.</p>
</dl><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>errback<code>function(*): (R|IThenable<R>)</code><dd><p>The
function to call if this promise is rejected. The function should
expect a single argument: the rejection reason.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>A new promise which will be
resolved with the result of the invoked callback.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="thenFinally" class="function"><div><h3>thenFinally(<wbr>callback)<span class="codelink"><a href="source/lib/webdriver/promise.js.src.html#l749">code »</a></span></h3><div class="tags"><span>deprecated</span></div><p>Registers a listener to invoke when this promise is resolved, regardless
of whether the promise's value was successfully computed. This function
is synonymous with the <code>finally</code> clause in a synchronous API:</p>
<pre><code>// Synchronous API:
try {
doSynchronousWork();
} finally {
cleanUp();
}
// Asynchronous promise API:
doAsynchronousWork().thenFinally(cleanUp);
</code></pre>
<p><strong>Note:</strong> similar to the <code>finally</code> clause, if the registered
callback returns a rejected promise or throws an error, it will silently
replace the rejection error (if any) from this promise:</p>
<pre><code>try {
throw Error('one');
} finally {
throw Error('two'); // Hides Error: one
}
promise.rejected(Error('one'))
.thenFinally(function() {
throw Error('two'); // Hides Error: one
});
</code></pre>
<p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#thenFinally">webdriver.promise.Thenable</a></p><dl><dt>Deprecated<dd><p>Use <code>thenFinally</code> from the promise property directly.</p>
</dl><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>callback<code>function(): (R|IThenable<R>)</code><dd><p>The function
to call when this promise is resolved.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>A promise that will be fulfilled
with the callback result.</p>
</dl></div></div></div></div><h2>Instance Properties</h2><div id="promise" class="property"><dl><dt><a href="source/lib/webdriver/promise.js.src.html#l680">promise</a><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><T></code><dd>No description.</dl></div></article><nav><h3><a href="index.html" tabindex="2">Overview</a></h3><div><input type="checkbox" id="nav-modules" checked/><label for="nav-modules"><h3><span class="selectable" tabindex="2">Modules</span></h3></label><div id="nav-modules-view"></div></div><div><input type="checkbox" id="nav-types" checked/><label for="nav-types"><h3><span class="selectable" tabindex="2">Types</span></h3></label><div id="nav-types-view"></div></div><h3><a href="Changes.html" tabindex="2">Changes</a></h3></nav></main><footer><div><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></div></footer><script src="types.js"></script><script src="dossier.js"></script>