Package Torello.Browser
Class Promise<RESULT>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<RESULT>
-
- Torello.Browser.Promise<RESULT>
-
- Type Parameters:
RESULT- This type indicates the type used by return-value that's ultimately received by the user. This type is the class which is actually returned when a user makes a call toPromise.await().
- All Implemented Interfaces:
java.util.concurrent.CompletionStage<RESULT>,java.util.concurrent.Future<RESULT>
public class Promise<RESULT> extends java.util.concurrent.CompletableFuture<RESULT>
Primarily a wrapper around Java'sCompletableFuturethat provides two or three simplified methods for awaiting a promise.
The three classes,Script,PromiseandSenderare designed to allow for the creation of 'Asynchronous Scripts' that may be executed and made to appear to be synchronous through thePromise.await()method.
These three classes are made use of in the Browser Remote Debugging Protocol Package. Theoretically, they could be used by any asynchronous communication system.
Hi-Lited Source-Code:- View Here: Torello/Browser/Promise.java
- Open New Browser-Tab: Torello/Browser/Promise.java
File Size: 5,180 Bytes Line Count: 132 '\n' Characters Found
-
-
Field Summary
The Script which has made this Promise Modifier and Type Field Script<RESULT>scriptThe JsonObject that has produced the RESULT Modifier and Type Field JsonObjectjo
-
Method Summary
Waits for this Promise to resolve, and return a RESULT, or throw. Modifier and Type Method RESULTawait()RESULTawait(long timeout, TimeUnit unit)-
Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
-
-
-
Field Detail
-
script
-
jo
public volatile JsonObject jo
This field will hold the json response which has been recived by theWebSocket'slayer. This field is assigned immediately preceeding this future's completion. The json stored here will only be the"result"property of the surrounding datagram json envelope.
Because CDP may or may not be a "moving target", this field is provided as a manner of conenience to the developer's wanting to see how their response POJO's were built. In normal operations, there is likely little use for inspecting the raw protocol json.This field is updated by the response handler's immediately prior to invoking theCompletableFuture.completemethod. It is initialized to null. There are also logs which contain the json that has been sent and received over the WebSocket's layer, although they are less convenient to use.- Code:
- Exact Field Declaration Expression:
public volatile JsonObject jo = null;
-
-
Method Detail
-
await
public RESULT await()
Nearly identical to theCompletableFuturemethodjoin.This method is nothing more than a wrapper around theCompletableFuturemethod known asjoin(long). This does a little bit of Exception Unwrapping, as may be viewed in the Hi-Lited Code, below.- Returns:
- the long-lost, long-awaited-for, result.
- Code:
- Exact Method Body:
try { return this.join(); } catch (CompletionException e) { Throwable c = e.getCause(); if (c == null) throw e; if (c instanceof RDPException) throw (RDPException) c; if (c instanceof BrowserException) throw (BrowserException) c; if (c instanceof BrowserErrorException) throw (BrowserErrorException) c; if (c instanceof AsynchronousException) throw (AsynchronousException) c; throw e; }
-
await
public RESULT await(long timeout, java.util.concurrent.TimeUnit unit)
Waits if necessary for at most the given time for this future to complete, and then returns its result, if available.This method is nothing more than a wrapper around theCompletableFuturemethod known asget(long, TimeUnit). This method simply converts a slew of Checked-Exceptions into Unchecked / RuntimeExceptions. No more, no less.- Parameters:
timeout- The maximum time to waitunit- the time unit of the timeout parameter- Returns:
- the result value
- Throws:
UncheckedExecutionException- if this future completed exceptionallyUncheckedInterruptedException- if the current thread was interrupted while waitingUncheckedTimeoutException- if the waiting timed outjava.util.concurrent.CompletionException- if this future was cancelledRDPExceptionBrowserExceptionBrowserErrorExceptionAsynchronousException- Code:
- Exact Method Body:
try { return this.get(timeout, unit); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } catch (InterruptedException e) { throw new UncheckedInterruptedException(e); } catch (TimeoutException e) { throw new UncheckedTimeoutException(e); } catch (CompletionException e) { Throwable c = e.getCause(); if (c == null) throw e; if (c instanceof RDPException) throw (RDPException) c; if (c instanceof BrowserException) throw (BrowserException) c; if (c instanceof BrowserErrorException) throw (BrowserErrorException) c; if (c instanceof AsynchronousException) throw (AsynchronousException) c; throw e; }
-
-