workerd icon indicating copy to clipboard operation
workerd copied to clipboard

Support passing a AbortSignal to cache.match

Open SamyPesse opened this issue 1 year ago • 2 comments

Because of how Cloudflare is tracing async executions (https://zuplo.com/blog/2022/03/04/the-script-will-never-generate-a-response), when implementing concurrent logic with Promise.race or similar, it's prefered to use a signal to abort any underlying fetch.

For example in my case I want to read from multiple caches in parallel, and one of them is the caches.default. But in theory the script might respond before all the caches finished responding.

It'd be great if we could pass a AbortSignal to cache.match:

const abort = new AbortController();
const response = await cache.match(request, { signal: abort.signal });

SamyPesse avatar Dec 21 '23 20:12 SamyPesse

fyi ... @irvinebroque

jasnell avatar Dec 21 '23 21:12 jasnell

While we do already have some variances from the standard Cache API (https://developer.mozilla.org/en-US/docs/Web/API/Cache/match) I would be hesitant adding a non-standard option for a signal here. My preference would be to try to have the standard options updated to include a signal option that would parallel the option in fetch.

On a technical level, implementing this would not be difficult, however, and I think it would be a valuable addition.

jasnell avatar Jan 03 '24 00:01 jasnell