I saw the talk and it was horrifying, I hope the issue is resolved now!
I saw the talk and it was horrifying, I hope the issue is resolved now!

ctx.waitUntil(foo()) not ctx.waitUntil(await foo())
waitUntil will keep your Worker alive, after returning a Response, until the promise resolves.canceled or daemon_down
for await (const variationResponse of variationResponses) it will do one at a timectx.waitUntil(foo())ctx.waitUntil(await foo())waitUntilResponsecanceleddaemon_downfor await (const variationResponse of variationResponses)async function doStuff() {
await scheduler.wait(1000);
console.log('foo');
}
export default {
async fetch(req, env, ctx) {
ctx.waitUntil(doStuff());
return new Response('bar');
}
}export default {
async fetch(req, env, ctx) {
ctx.waitUntil(doStuff());
console.log('bar')
return new Response(null);
}
}bar
13:29:15 GET / 200
fooexport default {
async fetch(req, env, ctx) {
ctx.waitUntil(await doStuff());
console.log('bar')
return new Response(null);
}
}foo
bar
13:30:16 GET / 200 const variationR2Results: Array<{ width: number; id: string }> = [];
for (const variationResponse of variationResponses) {
const result = await context.env.MY_BUCKET.put(
variationResponse.key,
variationResponse.response.body,
{
httpMetadata: {
contentType,
},
}
);
variationR2Results.push({
id: result.key,
width: variationResponse.width,
});
}async function createAllVariationsForR2Image({
originalId,
originalUrl,
imgProxyKey,
imgProxySalt,
imgProxyUrl,
}: CreateAllVariationsForR2ImageOptions) {
const source = stringToBase64Url(originalUrl);
const limit = plimit(3);
const promises: Promise<{
response: Response;
width: number;
key: string;
}>[] = [];
const lastDotIndex = originalId.lastIndexOf(".");
const baseName = originalId.slice(0, lastDotIndex);
const extension = originalId.slice(lastDotIndex + 1);
for (const variation of variations) {
for (const dpr of [1, 2]) {
const path = `/rs:fit:${variation.width}:0/dpr:${dpr}/${source}`;
const signature = await sign(imgProxySalt, path, imgProxyKey);
const resizeUrl = `${imgProxyUrl}/${signature}${path}`;
console.log("resizeUrl", resizeUrl);
promises.push(
limit(async () => {
const response = await fetch(resizeUrl);
return {
response,
width: variation.width,
key: `${baseName}_${variation.id}_${dpr}x.${extension}`,
};
})
);
}
}
const resolvedPromises = await Promise.all(promises);
return resolvedPromises;
}