Skip to content

Commit

Permalink
return isReady in connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornos committed Oct 23, 2024
1 parent 460eca3 commit 8b7bb44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions packages/server/src/services/networking/client/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { ApiClient, ApiContext } from './types.js'

export async function createArchiveClient(log: Logger, chainId: string, url: string | Array<string>) {
const client = new ArchiveClient(log, chainId, url)
client.connect()
return await client.isReady()
return await client.connect()
}

/**
Expand Down Expand Up @@ -143,15 +142,18 @@ export class ArchiveClient extends EventEmitter implements ApiClient {
return codec.dec(await this.getStorage(codec.enc(...args)))
}

async connect() {
try {
const ctx = new RuntimeApiContext(await this.#runtimeContext)
this.#apiContext = () => ctx
super.emit('connected')
this.#connected = true
} catch (error) {
this.#log.error(error, '[client:%s] error while connecting %s (should never happen)', this.chainId)
}
connect() {
this.#runtimeContext
.then((x) => {
const ctx = new RuntimeApiContext(x)
this.#apiContext = () => ctx
super.emit('connected')
this.#connected = true
})
.catch((error) => {
this.#log.error(error, '[client:%s] error while connecting %s (should never happen)', this.chainId)
})
return this.isReady()
}

disconnect() {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/networking/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ApiClient {
readonly finalizedHeads$: Observable<BlockInfo>
readonly ctx: ApiContext

connect(): Promise<void>
connect(): Promise<ApiClient>
disconnect(): void

getMetadata(): Promise<Uint8Array>
Expand Down

0 comments on commit 8b7bb44

Please sign in to comment.