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

orm-types
Garrett Mills 2 years ago
parent dbe48ea8a5
commit a590d78155

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

@ -147,7 +147,7 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
/** Connect an external event bus to this bus. */ /** Connect an external event bus to this bus. */
async connect(bus: EventBus): Promise<void> { async connect(bus: EventBus): Promise<void> {
if ( this.isUp ) { if ( this.isUp && !bus.isConnected() ) {
await bus.up() 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> { async disconnect(bus: EventBus): Promise<void> {
await this.subscriptions await this.subscriptions
.where('busUuid', '=', bus.uuid) .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 this.isUp = true
} }

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

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

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

Loading…
Cancel
Save