From 79c5d8d76512b641167bce46e82f34cf22bc285e Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Sun, 24 Jul 2022 16:28:23 +0200 Subject: [PATCH] feat(routing): support promise in message repo (#959) Signed-off-by: Timo Glastra --- packages/core/src/agent/MessageSender.ts | 4 ++-- .../src/modules/routing/services/MessagePickupService.ts | 6 +++--- packages/core/src/storage/MessageRepository.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/src/agent/MessageSender.ts b/packages/core/src/agent/MessageSender.ts index baf9f2f22b..83e5a717b7 100644 --- a/packages/core/src/agent/MessageSender.ts +++ b/packages/core/src/agent/MessageSender.ts @@ -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 } @@ -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 } diff --git a/packages/core/src/modules/routing/services/MessagePickupService.ts b/packages/core/src/modules/routing/services/MessagePickupService.ts index 5ab803ae99..cc02a2e3cc 100644 --- a/packages/core/src/modules/routing/services/MessagePickupService.ts +++ b/packages/core/src/modules/routing/services/MessagePickupService.ts @@ -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 @@ -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) } } diff --git a/packages/core/src/storage/MessageRepository.ts b/packages/core/src/storage/MessageRepository.ts index e56830bc4a..75fcd0cbd1 100644 --- a/packages/core/src/storage/MessageRepository.ts +++ b/packages/core/src/storage/MessageRepository.ts @@ -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 + add(connectionId: string, payload: EncryptedMessage): void | Promise }