Reduce # of duplicate Bus.up() calls; bump version

This commit is contained in:
Garrett Mills 2022-03-30 17:34:19 -05:00
parent dbe48ea8a5
commit a590d78155
5 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.7",
"version": "0.9.8",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@ -147,7 +147,7 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
/** Connect an external event bus to this bus. */
async connect(bus: EventBus): Promise<void> {
if ( this.isUp ) {
if ( this.isUp && !bus.isConnected() ) {
await bus.up()
}
@ -167,6 +167,10 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
})
}
isConnected(): boolean {
return this.isUp
}
async disconnect(bus: EventBus): Promise<void> {
await this.subscriptions
.where('busUuid', '=', bus.uuid)
@ -202,7 +206,9 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
}
}
await this.connectors.awaitMapCall('up')
await this.connectors
.filter(bus => !bus.isConnected())
.awaitMapCall('up')
this.isUp = true
}

View File

@ -118,6 +118,10 @@ export class LocalBus<TEvent extends Event = Event> extends CanonicalItemClass i
this.isUp = true
}
isConnected(): boolean {
return this.isUp
}
/** Clean up this event bus. */
async down(): Promise<void> {
if ( !this.isUp ) {

View File

@ -104,6 +104,10 @@ export class RedisBus implements EventBus {
.awaitAll()
}
isConnected(): boolean {
return Boolean(this.subscriberConnection && this.publisherConnection)
}
async up(): Promise<void> {
this.subscriberConnection = await this.redis.getNewConnection()
this.publisherConnection = await this.redis.getNewConnection()

View File

@ -75,6 +75,8 @@ export interface EventBus<TEvent extends Event = Event> {
up(): Awaitable<void>
down(): Awaitable<void>
isConnected(): boolean
}
/** Internal storage format for local event bus subscribers. */