Skip to content

Commit

Permalink
Scheduling APIs: Use abort reason in postTask
Browse files Browse the repository at this point in the history
This updates postTask to use the abort reason when rejecting the
associated promise due to a signal aborting. If no abort reason is
specified during abort(), the reason defaults to an AbortError, which is
the current behavior. Given this and the newness of the API, the impact
of this change should be minimal.

Spec PR: WICG/scheduling-apis#53

Bug: 1272822
Change-Id: Ia1dbf93e2d7e1b2e507609d0cb6f93f67deddc4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3611791
Reviewed-by: Nate Chapin <[email protected]>
Commit-Queue: Scott Haseley <[email protected]>
Cr-Commit-Position: refs/heads/main@{#997819}
  • Loading branch information
shaseley authored and chromium-wpt-export-bot committed Apr 29, 2022
1 parent 4851bc6 commit 4ae557c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scheduler/post-task-abort-reason.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// META: title=Scheduler: postTask uses abort reason
// META: global=window,worker
'use strict';

promise_test(t => {
const controller = new TaskController();
const signal = controller.signal;
const reason = new Error("Custom Abort Error");
controller.abort(reason);
return promise_rejects_exactly(t, reason, scheduler.postTask(() => {}, {signal}));
}, 'Calling postTask with an aborted TaskSignal rejects the promise with the abort reason');

promise_test(t => {
const controller = new AbortController();
const signal = controller.signal;
const reason = new Error("Custom Abort Error");
controller.abort(reason);
return promise_rejects_exactly(t, reason, scheduler.postTask(() => {}, {signal}));
}, 'Calling postTask with an aborted AbortSignal rejects the promise with the abort reason');

promise_test(t => {
const controller = new TaskController();
const signal = controller.signal;
const reason = new Error("Custom Abort Error");
const result = scheduler.postTask(() => {}, {signal});
controller.abort(reason);
return promise_rejects_exactly(t, reason, result);
}, 'Aborting a TaskSignal rejects the promise of a scheduled task with the abort reason');

promise_test(t => {
const reason = new Error("Custom Abort Error");
const controller = new AbortController();
const signal = controller.signal;
const result = scheduler.postTask(() => {}, {signal});
controller.abort(reason);
return promise_rejects_exactly(t, reason, result);
}, 'Aborting an AbortSignal rejects the promise of a scheduled task with the abort reason');

0 comments on commit 4ae557c

Please sign in to comment.