Back to Content

TaskSignal

files/en-us/web/api/tasksignal/index.md

latest2.8 KB
Original Source

{{APIRef("Prioritized Task Scheduling API")}}{{AvailableInWorkers}}

The TaskSignal interface of the Prioritized Task Scheduling API represents a signal object that allows you to communicate with a prioritized task, and abort it or change the priority (if required) via a {{domxref('TaskController')}} object.

An object of this type is created, and associated with, a {{domxref('TaskController')}}. The initial priority of the signal may be set by specifying it as an argument to the {{domxref("TaskController.TaskController", "TaskController()")}} constructor (by default it is "user-visible"). The priority can be changed by calling {{domxref("TaskController.setPriority()")}} on the controller.

The signal may be passed as the options.signal argument in {{domxref("Scheduler.postTask()")}}, after which its associated controller can be used to abort the task. If the task priority is mutable, the controller can also be used to change the task's priority. Abortable tasks that do not need the priority to change may instead specify an {{domxref("AbortSignal")}} as the options.signal argument.

{{InheritanceDiagram}}

Instance properties

The TaskSignal interface also inherits properties from its parent interface, {{domxref("AbortSignal")}}.

  • {{domxref('TaskSignal.priority')}} {{ReadOnlyInline}}
    • : Returns the priority of the signal.

Static methods

The TaskSignal interface inherits methods from its parent interface, {{domxref("AbortSignal")}}.

  • {{domxref("TaskSignal/any_static", "TaskSignal.any()")}}
    • : Returns a TaskSignal that aborts when any of the given abort signals abort.

Instance methods

The TaskSignal interface inherits methods from its parent interface, {{domxref("AbortSignal")}}.

Events

Listen to these events using {{domxref("EventTarget.addEventListener()", "addEventListener()")}} or by assigning an event listener to the oneventname property of this interface.

  • {{domxref("TaskSignal/prioritychange_event", "prioritychange")}}
    • : Fired when the priority is changed. This is triggered by calling {{domxref('TaskController.setPriority()')}} on the associated controller.

Examples

Examples for how the TaskSignal is created and used for prioritizing and aborting tasks can be found here:

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}