forked from zwave-js/node-zwave-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
40 lines (33 loc) · 849 Bytes
/
test.ts
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
import { wait } from "alcalzone-shared/async";
import stream from "stream";
const queue = new stream.PassThrough({ objectMode: true });
interface Item {
id: number;
}
process.nextTick(async () => {
for await (const item of queue as AsyncIterable<Item>) {
console.log("processing item", item.id);
await wait(250);
console.log("finished item", item.id);
console.log();
}
console.log("queue finished");
});
async function main() {
console.log("adding item", 1);
queue.write({ id: 1 });
await wait(100);
console.log("adding item", 2);
queue.write({ id: 2 });
console.log("adding item", 3);
queue.write({ id: 3 });
await wait(1000);
console.log("adding item", 4);
queue.write({ id: 4 });
await wait(2000);
console.log("adding item", 5);
queue.write({ id: 5 });
console.log("closing stream");
queue.end();
}
void main();