MCPcopy Index your code
hub / github.com/Sandpack/nodebox-runtime / foo

Function foo

tests/examples/timers.example.js:10–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8 */
9window.runExample = async function (emulatorUrl) {
10 const foo = async () => {
11 const { Nodebox } = window;
12
13 const emulator = new Nodebox({
14 runtimeUrl: emulatorUrl,
15 iframe: document.getElementById('frame'),
16 });
17
18 await emulator.connect();
19 await emulator.fs.init({
20 'index.mjs': `import timers from "timers/promises";
21
22async function run() {
23 console.log("Start timers");
24 console.log(await timers.setTimeout(1500, "test timeout"));
25 console.log(await timers.setImmediate("immediate"));
26
27 const interval = 100;
28 for await (const startTime of timers.setInterval(interval, Date.now())) {
29 const now = Date.now();
30 console.log(now);
31 if (now - startTime > 1000) {
32 break;
33 }
34 }
35}
36
37run().catch(console.error);
38`,
39 });
40
41 const shellProcess = emulator.shell.create();
42
43 return new Promise(async (resolve) => {
44 shellProcess.stdout.on('data', (data) => {
45 return resolve(data);
46 });
47
48 await shellProcess.runCommand('node', ['index.mjs']);
49 });
50 };
51
52 console.log(await foo());
53};

Callers 1

timers.example.jsFile · 0.70

Calls 5

connectMethod · 0.95
initMethod · 0.80
createMethod · 0.80
runCommandMethod · 0.80
onMethod · 0.45

Tested by

no test coverage detected