According to MDN, messages in the JavaScript event loop “run to completion”.
(https://developer.mozilla.org/docs/Web/JavaScript/Event_loop#run-to-completion)
But I have created a case where this does not seem to happen.
abortController1 = new AbortController()
abortController2 = new AbortController()
abortController1.signal.addEventListener("abort", () =>
{
console.log("abort 1 start")
abortController2.abort()
console.log("abort 1 end")
})
abortController2.signal.addEventListener("abort", () =>
{
console.log("abort 2")
})
abortController1.abort()
Output:
abort 1 start
abort 2
abort 1 end
I was expecting to see this output:
abort 1 start
abort 1 end
abort 2
Can someone please explain what’s going on here?