Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

inconsistency: top-level setTimeout, others #148

Open
iameli opened this issue Mar 8, 2020 · 2 comments
Open

inconsistency: top-level setTimeout, others #148

iameli opened this issue Mar 8, 2020 · 2 comments

Comments

@iameli
Copy link

iameli commented Mar 8, 2020

Simple test case:

setTimeout(() => {}, 0)

This works in cloudworker but fails in CF workers, with this error:

Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request

We should disallow the same behavior and add tests for all cases we can think of.

@xtuc
Copy link

xtuc commented Mar 9, 2020

It fails in the preview but I'm sure it works in production, have you tried it?

@iameli
Copy link
Author

iameli commented Mar 9, 2020

Hmm. Just tossing a single setTimeout(() => {}, 0) into an existing worker script seems to not break, but actually relying on a top-level timeout to do anything doesn't seem to work. I deployed this with wrangler and it didn't work, for example:

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request));
});

const prom = new Promise(resolve =>
  setTimeout(() => {
    resolve("hello from async");
  }, 0)
);

async function handleRequest(request) {
  const data = await prom;
  return new Response(data, { status: 200 });
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants