Add Executor and RelaySet

This commit is contained in:
Jonathan Staab
2023-03-27 13:39:48 -05:00
parent 4b362e3061
commit 853b42c1c9
9 changed files with 121 additions and 72 deletions
+24
View File
@@ -0,0 +1,24 @@
import type {Relay} from './Relay'
import {EventBus} from './util/EventBus'
export class RelaySet {
relays: Relay[]
bus: EventBus
constructor(relays) {
this.relays = relays
this.bus = new EventBus()
relays.forEach(relay => {
relay.bus.pipe(EventBus.ANY, this.bus)
})
}
send(...payload) {
this.relays.forEach(async relay => {
await relay.connect()
if (relay.status === Relay.STATUS.READY) {
relay.send(...payload)
}
})
}
}