Reduce # of duplicate Bus.up() calls; bump version
This commit is contained in:
parent
dbe48ea8a5
commit
a590d78155
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 ) {
|
||||
|
@ -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()
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user