Class AbortSignal
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The AbortSignal interface represents a signal object that allows you to communicate with an asynchronous operation (such as a fetch request) and abort it if required via an AbortController object.
[Value("AbortSignal")]
public class AbortSignal : EventTarget
- Inheritance
-
AbortSignal
- Derived
- Inherited Members
Remarks
-Fetch API
-Abortable Fetch by Jake Archibald
Constructors
AbortSignal()
public AbortSignal()
Properties
Aborted
The aborted read-only property returns a value that indicates whether the asynchronous operations the signal is communicating with are aborted (true) or not (false).
[Value("aborted")]
public bool Aborted { get; }
Property Value
- bool
true(aborted) orfalse
Remarks
Onabort
[Value("onabort")]
public EventHandlerNonNull Onabort { get; set; }
Property Value
Reason
The reason read-only property returns a JavaScript value that indicates the abort reason.
[Value("reason")]
public dynamic Reason { get; }
Property Value
- dynamic
A JavaScript value that indicates the abort reason, or
undefined, if not aborted.
Remarks
The property is undefined when the signal has not been aborted.
It can be set to a specific value when the signal is aborted, using Abort(dynamic) or AbortSignalabort.
If not explicitly set in those methods, it defaults to "AbortError" DOMException.
Methods
Abort(dynamic)
The abort event of the AbortSignal is fired when the associated request is aborted, i.e., using Abort(dynamic).
[Value("abort")]
public static AbortSignal Abort(dynamic reason = null)
Parameters
reasondynamic
Returns
- AbortSignal
An
AbortSignalinstance with the Aborted property set totrue, and Reason set to the specified or default reason value.
Remarks
Any(List<AbortSignal>)
The AbortSignal.any() static method takes an iterable of abort signals and returns an AbortSignal. The returned abort signal is aborted when any of the input iterable abort signals are aborted. The {{domxref("AbortSignal.reason", "abort reason","","true")}} will be set to the reason of the first signal that is aborted. If any of the given abort signals are already aborted then so will be the returned AbortSignal.
[Value("any")]
public static AbortSignal Any(List<AbortSignal> signals)
Parameters
signalsList<AbortSignal>
Returns
- AbortSignal
A AbortSignal that is:
Remarks
ThrowIfAborted()
The throwIfAborted() method throws the signal's abort Reason if the signal has been aborted; otherwise it does nothing.
[Value("throwIfAborted")]
public GlobalObject.Undefined ThrowIfAborted()
Returns
Remarks
An API that needs to support aborting can accept an AbortSignal object and use throwIfAborted() to test and throw when the abort event is signalled.
This method can also be used to abort operations at particular points in code, rather than passing to functions that take a signal.
Timeout(ulong)
The AbortSignal.timeout() static method returns an AbortSignal that will automatically abort after a specified time.
[Value("timeout")]
public static AbortSignal Timeout(ulong milliseconds)
Parameters
millisecondsulong
Returns
- AbortSignal
An AbortSignal.The signal will abort with its Reason property set to a
TimeoutErrorDOMException on timeout, or anAbortErrorDOMException if the operation was user-triggered.
Remarks
The signal aborts with a TimeoutError DOMException on timeout.
The timeout is based on active rather than elapsed time, and will effectively be paused if the code is running in a suspended worker, or while the document is in a back-forward cache ("bfcache").
To combine multiple signals, you can use AbortSignalany, for example, to directly abort a download using either a timeout signal or by calling Abort(dynamic).