maxm-robpikeio.web.val.run
Readme

robpike.io

A re-implementation of https://robpike.io/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const msg = new TextEncoder().encode("💩");
const initialDelay = 20;
export default async function(req: Request): Promise<Response> {
let timerId: number | undefined;
const body = new ReadableStream({
start(controller) {
let currentDelay = initialDelay;
function writeToStream() {
currentDelay *= 1.03;
controller.enqueue(msg);
timerId = setTimeout(writeToStream, currentDelay);
}
writeToStream();
},
cancel() {
if (typeof timerId === "number") {
clearInterval(timerId);
}
},
});
return new Response(body, {
headers: {
"Content-Type": "text/event-stream",
},
});
}
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!
v11
June 7, 2024