ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
new AbortController(), AbortSignal.abort(), new WritableStream(), and request.signal no longer throw when used during module evaluation (that is, at the top level of your Worker module, outside of a request handler). Previously, these APIs required an active request context and would throw if called at the top level.
Code:
// This now works — no error during module startup
const controller = new AbortController();
export default {
async fetch(request) {
// The signal can be used across requests
return new Response("OK", { signal: controller.signal });
},
};
Signals can also be observed and aborted across different requests, making it easier to coordinate cancellation in long-lived Workers such as Durable Objects.
AbortSignal.timeout() still requires an active request context because it needs to schedule a timer.For more details, refer to the AbortController documentation.
Continue reading...