Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set priority on TaskController instead of on postTask/yield #27295

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/scheduler/src/__tests__/SchedulerPostTask-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ describe('SchedulerPostTask', () => {
const scheduler = {};
global.scheduler = scheduler;

scheduler.postTask = function (callback, {priority, signal}) {
scheduler.postTask = function (callback, {signal}) {
const {priority} = signal;
const id = idCounter++;
log(
`Post Task ${id} [${priority === undefined ? '<default>' : priority}]`,
Expand All @@ -94,7 +95,8 @@ describe('SchedulerPostTask', () => {
});
};

scheduler.yield = function ({priority, signal}) {
scheduler.yield = function ({signal}) {
const {priority} = signal;
const id = idCounter++;
log(`Yield ${id} [${priority === undefined ? '<default>' : priority}]`);
const controller = signal._controller;
Expand All @@ -111,8 +113,8 @@ describe('SchedulerPostTask', () => {
};

global.TaskController = class TaskController {
constructor() {
this.signal = {_controller: this};
constructor({priority}) {
this.signal = {_controller: this, priority};
}
abort() {
const task = taskQueue.get(this);
Expand Down
10 changes: 5 additions & 5 deletions packages/scheduler/src/forks/SchedulerPostTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {PriorityLevel} from '../SchedulerPriorities';

declare class TaskController {
constructor(priority?: string): TaskController;
constructor(options?: {priority?: string}): TaskController;
signal: mixed;
abort(): void;
}
Expand Down Expand Up @@ -95,9 +95,8 @@ export function unstable_scheduleCallback<T>(
break;
}

const controller = new TaskController();
const controller = new TaskController({priority: postTaskPriority});
const postTaskOptions = {
priority: postTaskPriority,
delay: typeof options === 'object' && options !== null ? options.delay : 0,
signal: controller.signal,
};
Expand Down Expand Up @@ -130,9 +129,10 @@ function runTask<T>(
if (typeof result === 'function') {
// Assume this is a continuation
const continuation: SchedulerCallback<T> = (result: any);
const continuationController = new TaskController();
const continuationOptions = {
const continuationController = new TaskController({
priority: postTaskPriority,
});
const continuationOptions = {
signal: continuationController.signal,
};
// Update the original callback node's controller, since even though we're
Expand Down