-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathserver-function-ping.tsx
More file actions
43 lines (36 loc) · 927 Bytes
/
server-function-ping.tsx
File metadata and controls
43 lines (36 loc) · 927 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createEffect, createSignal } from "solid-js";
async function sleep(value: unknown, ms: number) {
return new Promise((res) => {
setTimeout(res, ms, value);
})
}
async function ping(value: Date) {
"use server";
const current = [
value,
{
name: 'example',
async *[Symbol.asyncIterator]() {
yield sleep('foo', 5000);
yield sleep('bar', 5000);
yield sleep('baz', 5000);
}
}
];
return current;
}
export default function App() {
const [output, setOutput] = createSignal<{ result?: boolean }>({});
createEffect(async () => {
const value = new Date();
const result = await ping(value);
await ping(value);
console.log(result);
setOutput((prev) => ({ ...prev, result: value.toString() === result[0].toString() }));
});
return (
<main>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
);
}