Files: fb80c5e51c634a7cd505d71b34160b19f451cd16 / port.js
454 bytesRaw
1 | const EventEmitter = require('events') |
2 | |
3 | module.exports = class Port extends EventEmitter { |
4 | constructor () { |
5 | super() |
6 | this.queue = [] |
7 | } |
8 | |
9 | connect (destPort) { |
10 | this.destPort = destPort |
11 | destPort.destPort = this |
12 | } |
13 | |
14 | async send (message) { |
15 | return this.destPort.recieve(message) |
16 | } |
17 | |
18 | async recieve (message) { |
19 | this.emit('message', message) |
20 | this.queue.push(message) |
21 | } |
22 | |
23 | dequeue () { |
24 | return this.queue.unshift() |
25 | } |
26 | } |
27 |
Built with git-ssb-web