Skip to content

Commit

Permalink
feat(routing): support promise in message repo (#959)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Jul 24, 2022
1 parent 3e415d8 commit 79c5d8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class MessageSender {
// If the other party shared a queue service endpoint in their did doc we queue the message
if (queueService) {
this.logger.debug(`Queue packed message for connection ${connection.id} (${connection.theirLabel})`)
this.messageRepository.add(connection.id, encryptedMessage)
await this.messageRepository.add(connection.id, encryptedMessage)
return
}

Expand Down Expand Up @@ -267,7 +267,7 @@ export class MessageSender {
}

const encryptedMessage = await this.envelopeService.packMessage(payload, keys)
this.messageRepository.add(connection.id, encryptedMessage)
await this.messageRepository.add(connection.id, encryptedMessage)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MessagePickupService {
const connection = messageContext.assertReadyConnection()

const { message } = messageContext
const messages = this.messageRepository.takeFromQueue(connection.id, message.batchSize)
const messages = await this.messageRepository.takeFromQueue(connection.id, message.batchSize)

// TODO: each message should be stored with an id. to be able to conform to the id property
// of batch message
Expand All @@ -39,7 +39,7 @@ export class MessagePickupService {
return createOutboundMessage(connection, batchMessage)
}

public queueMessage(connectionId: string, message: EncryptedMessage) {
this.messageRepository.add(connectionId, message)
public async queueMessage(connectionId: string, message: EncryptedMessage) {
await this.messageRepository.add(connectionId, message)
}
}
4 changes: 2 additions & 2 deletions packages/core/src/storage/MessageRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EncryptedMessage } from '../types'

export interface MessageRepository {
takeFromQueue(connectionId: string, limit?: number): EncryptedMessage[]
add(connectionId: string, payload: EncryptedMessage): void
takeFromQueue(connectionId: string, limit?: number): EncryptedMessage[] | Promise<EncryptedMessage[]>
add(connectionId: string, payload: EncryptedMessage): void | Promise<void>
}

0 comments on commit 79c5d8d

Please sign in to comment.