Skip to content

Commit

Permalink
refactor: start and stop transports in parallel (#705)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Apr 14, 2022
1 parent 549647d commit 858253a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,10 @@ export class Agent {
})
}

for (const transport of this.inboundTransports) {
await transport.start(this)
}

for (const transport of this.outboundTransports) {
await transport.start(this)
}
// Start transports
const allTransports = [...this.inboundTransports, ...this.outboundTransports]
const transportPromises = allTransports.map((transport) => transport.start(this))
await Promise.all(transportPromises)

// Connect to mediator through provided invitation if provided in config
// Also requests mediation ans sets as default mediator
Expand All @@ -200,12 +197,9 @@ export class Agent {
this.agentConfig.stop$.next(true)

// Stop transports
for (const transport of this.outboundTransports) {
await transport.stop()
}
for (const transport of this.inboundTransports) {
await transport.stop()
}
const allTransports = [...this.inboundTransports, ...this.outboundTransports]
const transportPromises = allTransports.map((transport) => transport.stop())
await Promise.all(transportPromises)

// close wallet if still initialized
if (this.wallet.isInitialized) {
Expand Down

0 comments on commit 858253a

Please sign in to comment.