Class ScriptOperation
await.
Methods that start such an operation return immediately; the work runs in
the background. Comparison.compare() and Comparison.print()
return a native JavaScript Promise; merge(), sync()
and report() return a ScriptOperation. Both are
thenables and are used the same way:
// Sequential: the report starts only after the comparison has finished
await comp.compare();
await comp.report(reportPath, ReportKind.HTML, null);
// Parallel: both comparisons run at the same time
await Promise.all([compA.compare(), compB.compare()]);
// Start now, await later
const op = comp.compare();
console.log('Comparison running...');
await op;
Failure and cancellation
An operation that fails rejects with a string describing the failure, for
instance when another operation is already pending on the same comparison.
An operation that is cancelled, for instance because its comparison was
closed while it was pending, rejects with a ScriptCancellationError
whose cancelled property is true:
try {
await comp.compare();
} catch (e) {
if (e.cancelled) {
console.log('Cancelled: ' + e.message);
} else {
console.error('Failed: ' + e);
}
}
If no pending operation completes within the script timeout - 5 minutes by
default, configurable with the JVM option
-Ddw.script.waitTimeoutMs=<ms> - the script itself is stopped with a
timeout error; this cannot be caught by the script.
Await a ScriptOperation returned by merge(), sync()
or report() only once. To await it several times, or to pass it to
Promise.all() more than once, wrap it first:
const p = Promise.resolve(comp.report(...));.
- Since:
- 3.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAnswers whether this operation has been cancelled.booleanAnswers whether this operation has completed successfully.Returns why this operation failed or was cancelled.The JavaScript thenable protocol: registers the functions to call when this operation settles.
-
Method Details
-
isResolved
public boolean isResolved()Answers whether this operation has completed successfully.- Returns:
trueif the operation has succeeded,falseif it is still pending, has failed or has been cancelled
-
isCancelled
public boolean isCancelled()Answers whether this operation has been cancelled.- Returns:
trueif the operation has been cancelled,falseotherwise
-
rejectionReason
Returns why this operation failed or was cancelled.- Returns:
- the failure or cancellation message, or
nullif the operation is pending or has succeeded
-
then
The JavaScript thenable protocol: registers the functions to call when this operation settles. The JavaScript engine calls this method when a scriptawaits the operation or passes it toPromise.resolve()orPromise.all(); scripts rarely need to call it directly.onFulfilledis called without arguments when the operation succeeds.onRejectedis called with a failure message, or with aScriptCancellationErrorwhen the operation is cancelled. Only the functions passed to the most recent call are kept.- Parameters:
onFulfilled- the function to call when the operation succeedsonRejected- the function to call when the operation fails or is cancelled- Returns:
- always
null; unlikePromise.then(), this method does not return a new promise
-