-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzle.js
More file actions
47 lines (37 loc) · 971 Bytes
/
puzzle.js
File metadata and controls
47 lines (37 loc) · 971 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
44
45
46
47
const { promisify } = require('util');
const sleep = promisify(setTimeout);
async function bar(n, s, t) {
setImmediate(() => process.stdout.write(s));
await sleep(n);
return t;
}
async function foo() {
process.stdout.write('L'); // 14
for (const m of await Promise.all(
[
bar(
20,
'N', // 9
'R' // 11
),
bar(
10,
'T', // 10
'E' // 12
)
]
))
process.stdout.write(m); // 15
}
sleep(50).then(() => process.stdout.write('A')); // 13
new Promise(res => {
process.stdout.write('H'); // 1
res('O'); // 5
}).then(m => process.stdout.write(m))
.finally(() => process.stdout.write('M')); // 7
queueMicrotask(() => process.stdout.write(' ')); // 6
process.nextTick(() => process.stdout.write('L')); // 3
setTimeout(() => process.stdout.write('L'), 100); // 4
setImmediate(() => process.stdout.write('O')); // 8 -> second event loop
process.stdout.write('E'); // 2
foo();