jamiedubs-sleeper.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// a very slow and sleepy function
// pass it ?sleep=33 to make it sleep for that amount of sleep
export default async function (req: Request): Promise<Response> {
const url = new URL(req.url);
const sleepQueryParam = url.searchParams.get('sleep');
let sleepTime = 1;
if (sleepQueryParam) {
sleepTime = parseInt(sleepQueryParam, 10);
if (!isNaN(sleepTime) && sleepTime > 0) {
await new Promise(resolve => setTimeout(resolve, sleepTime * 1000));
}
}
return new Response(JSON.stringify({ ok: true, sleepTime }), {
headers: { 'Content-Type': 'application/json' },
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 31, 2024