Class Scheduler
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The Scheduler interface of the Prioritized Task Scheduling API provides methods for scheduling prioritized tasks.
[Value("Scheduler")]
public class Scheduler
- Inheritance
-
Scheduler
- Inherited Members
Remarks
A Scheduler can be accessed from the global object using Window.Scheduler or WorkerGlobalScope.Scheduler within a worker.
Constructors
Scheduler()
public Scheduler()
Methods
PostTask(SchedulerPostTaskCallback, SchedulerPostTaskOptions)
The postTask() method of the Scheduler interface is used for adding tasks to be scheduled according to their priority.
[Value("postTask")]
public Task<dynamic> PostTask(SchedulerPostTaskCallback callback, SchedulerPostTaskOptions options = null)
Parameters
callbackSchedulerPostTaskCallbackoptionsSchedulerPostTaskOptions
Returns
- Task<dynamic>
Returns a Promise that is resolved with the return value of the
callbackfunction, or which may be rejected with thesignal's abort reason (Reason).
The promise may also be rejected with an error thrown by the callback during execution.
Remarks
The method allows users to optionally specify a minimum delay before the task will run, a priority for the task, and a signal that can be used to modify the task priority and/or abort the task.
It returns a promise that is resolved with the result of the task callback function, or rejected with the abort reason or an error thrown in the task.
Task priority can be mutable or immutable.
If the task priority will never need to change then it should be set using the options.priority parameter (any priority set through a signal will then be ignored).
You can still pass an AbortSignal (which has no priority) or TaskSignal to the options.signal parameter for aborting the task.
If the task priority might need to be changed the options.priority parameter must not be set.
Instead a TaskController should be created and its TaskSignal should be passed to options.signal.
The task priority will be initialized from the signal priority, and can later be modified using the signal's associated TaskController.
If no priority is set then the task priority defaults to "user-visible".
If a delay is specified and greater than 0, then the execution of the task will be delayed for at least that many milliseconds.
Otherwise the task is immediately scheduled for prioritization.
Yield()
The yield() method of the 'Scheduler' interface is used for yielding to the main thread during a task and continuing execution later, with the continuation scheduled as a prioritized task (see the Prioritized Task Scheduling API for more information). This allows long-running work to be broken up so the browser stays responsive.
[Value("yield")]
public Task<GlobalObject.Undefined> Yield()
Returns
- Task<GlobalObject.Undefined>
Returns a {{jsxref('Promise')}} that is fulfilled with {{jsxref('undefined')}}, or rejected with an 'AbortSignal.Reason'.
Remarks
The task can continue when the promise returned by the method is resolved. The priority for when the promise is resolved defaults to "user-visible", but can inherit a different priority if the yield() call occurs within a 'Scheduler.PostTask' callback.
In addition, the continuation of work after the yield() call can be canceled if it occurs within a postTask() callback and the task is aborted.
-Prioritized Task Scheduling API
-'Scheduler'
-'Scheduler.PostTask'