git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 48df42c8ab634c0d9fc7597e52106352878124fa

Files: 48df42c8ab634c0d9fc7597e52106352878124fa / port.js

496 bytesRaw
1const EventEmitter = require('events')
2
3module.exports = class Port extends EventEmitter {
4 constructor (name) {
5 super()
6 this.name = name
7 this.connected = false
8 }
9
10 connect (destPort) {
11 if (!this.connected) {
12 this.destPort = destPort
13 destPort.destPort = this
14 this.connected = true
15 }
16 }
17
18 async send (message) {
19 this.destPort.recieve(message)
20 }
21
22 async recieve (message) {
23 message.from.push(this.name)
24 this.emit('message', message)
25 }
26}
27

Built with git-ssb-web