2021/10/14 Workers Runtime Release Notes

Changes this week:

  • request.signal will always return an AbortSignal.
  • Cloudflare Workers’ integration with Chrome DevTools profiling now more accurately reports the line numbers and time elapsed. Previously, the line numbers were shown as one line later then the actual code, and the time shown would be proportional but much longer than the actual time used.
  • Upgrade to v8 9.5. See V8 release v9.5 · V8 for more details.
4 Likes

Hi,

Can you clarify this?

Do you mean that every Request() object will have a .signal property and calling .signal.abort() will abort the underlying Fetch() request?

What is the expected behavior when we call .signal.abort() on the Worker incoming request (which is also a Request())?

Thank you.

Hi @famzah,

Yes, but if the script didn’t provide the signal property during Request construction, then the signal property that is created is just a dummy object with no effect.

No, that’s not what AbortSignal.abort() does. AbortSignal.abort() is a static method which returns a new, immediately-aborted AbortSignal. It cannot be called on an actual AbortSignal object. In this way, it is conceptually similar to the Promise.reject() function, which creates new, immediately-rejected promises.

To use an AbortSignal to cancel a fetch(), first create an AbortController, pass its signal property to the Request constructor, and then you can call abort() on the AbortController to abort any fetch() using that Request.

Here’s an example: Cloudflare Workers

Harris

Thank you for the clarification and excuse my confusion about AbortSignal.abort().

Still I didn’t understand what’s request.signal useful for? Your example shows how to assign signal but not how to use it in the case we got it from the request.signal property.

Is its purpose that we subscribe to the abort event like shown in this example using
addEventListener() or .onabort? Are there other use-cases?

I think being able to subscribe to its abort event is probably the main purpose for exposing it. I’ve actually never used the AbortController/AbortSignal API myself, so I would defer to an expert.

1 Like