How do I issue an HTTP response after waiting for 3 seconds?

This topic was automatically generated from Slack. You can find the original thread here.

Raymond Camden : I know this is a dumb error on my part but - i’m building a test where I need PD to respond after 3 seconds. I did:

setTimeout(() => {
$respond({
  status: 200,
  headers: {
    "Content-Type": "text/html; charset=UTF-8"
  },
  body: html,
}) 
},3000)

And I get an error saying $respond wasn’t used. What did I miss? (The html variable is defined earlier.)

Giao Phan : The timeout isn’t a promise so it’s not being awaited.

Raymond Camden : ahhhh

Raymond Camden : thank you

Giao Phan : Something like await new Promise(resolve => setTimeout(() => { // your code; resolve()}, 3000))

Raymond Camden : got it working - gracias

Raymond Camden : i love async/await, still kinda feeling my way with it

Giao Phan : Yeah, building the product has taught me many fun things about using/abusing it.