-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (28 loc) · 750 Bytes
/
Copy pathindex.js
File metadata and controls
42 lines (28 loc) · 750 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
/**
* A basic example that logs each item from a Channel to the console.
* Try running this example yourself to see Downstream in action.
*/
const { Downstream, Channel } = require('downstream');
// a hook to log all items to the console
async function logHook(item, next) {
console.log(`Item #${item.i}`);
await next();
}
const channel = new Channel();
const downstream = new Downstream();
// register channels
downstream.register(channel);
// use hooks
downstream.use(logHook);
// log any errors
downstream.on('error', console.log);
(async () => {
// start Downstream
await downstream.start();
let i = 0;
// enqueue a new item every second
setInterval(() => {
channel.enqueue({ i });
i += 1;
}, 1000);
})();