Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems setTimeout is not working #29

Closed
sheerun opened this issue Feb 10, 2019 · 2 comments
Closed

It seems setTimeout is not working #29

sheerun opened this issue Feb 10, 2019 · 2 comments

Comments

@sheerun
Copy link
Contributor

sheerun commented Feb 10, 2019

The function I'm trying to use:

function sleep(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
}

I can see similar method working in tutorials like this: https://scotthelme.co.uk/unleashing-the-power-of-cloudflare-workers/

While testing with this package I get:

[0] ReferenceError: setTimeout is not defined
[0]     at resolve (evalmachine.<anonymous>:741:5)
[0]     at new Promise (<anonymous>)
@gja
Copy link
Owner

gja commented Feb 11, 2019

Hi. Could you elaborate a bit on your use case? I’ll add setTimeout, as I know that cloudflare does support it, but I’m curious, as I’m not sure cloudflare guarantees that it will wait for your callback to fire. IAC I’ll fix this in a day or two.

@sheerun
Copy link
Contributor Author

sheerun commented Feb 11, 2019

@gja Cloudflare supports construct like await sleep(1000) for the function above the same way as you can await fetch() when fetching external resources from cloudflare workers scripts.

My use case is to wait 2 seconds before answering Nexmo webhook what would simulate 2s delay before picking up the call

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

No branches or pull requests

2 participants