1

I recently found out about AbortController and its sibling AbortSignal to register event listeners until I don't want it anymore.

When I look at the documentation, it looks surprisingly similar to .NET CancellationTokenSource and CancellationToken, the controller has abort() method, the signal has aborted property and even a throwIfAborted() method.

However I am not sure if it was designed to be used internally by APIs like fetch and addEventListener only or can I use it for my own APIs like this?

function doSomething(input, ct) {
   ct?.throwIfAborted();
   await this.doStuff();
   ct?.throwIfAborted();
   // ...
}

Is there anything I should notice coming from .NET background that I should be aware of?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.