chore: return void for sds.sendMessage()

This commit is contained in:
Danish Arora 2025-08-30 17:25:12 +05:30
parent c64bcff475
commit 14d333ff0d
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
4 changed files with 22 additions and 24 deletions

View File

@ -1,3 +1,3 @@
export { AuthService, type AuthServiceInterface } from './AuthService';
export { AuthService, type AuthServiceInterface, type AuthResult } from './AuthService';
export { MessageService, type MessageServiceInterface } from './MessageService';
export { CryptoService, type CryptoServiceInterface, type DelegationDuration } from './CryptoService';

View File

@ -76,7 +76,7 @@ export class ReliableMessaging {
});
}
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> {
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
const channel = this.channels.get(message.type);
if (!channel) {
throw new Error(`No reliable channel for message type: ${message.type}`);
@ -90,8 +90,7 @@ export class ReliableMessaging {
}
try {
await channel.send(encodedMessage);
return messageId;
return channel.send(encodedMessage);
} catch (error) {
this.messageCallbacks.delete(messageId);
throw error;

View File

@ -90,11 +90,12 @@ class MessageManager {
return this.nodeManager.onHealthChange(callback);
}
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> {
//TODO: return event handlers?
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
if (!this.messageService) {
throw new Error("MessageManager not fully initialized");
}
return this.messageService.sendMessage(message, statusCallback);
this.messageService.sendMessage(message, statusCallback);
}
public onMessageReceived(callback: (message: OpchanMessage) => void): () => void {

View File

@ -28,7 +28,7 @@ export class MessageService {
}
}
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> {
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
if (!this.reliableMessaging) {
throw new Error("Reliable messaging not initialized");
}
@ -41,23 +41,21 @@ export class MessageService {
this.cacheService.updateCache(message);
// Send via reliable messaging with status tracking
const messageId = await this.reliableMessaging.sendMessage(message, {
onSent: (id) => {
console.log(`Message ${id} sent`);
statusCallback?.onSent?.(id);
},
onAcknowledged: (id) => {
console.log(`Message ${id} acknowledged`);
statusCallback?.onAcknowledged?.(id);
},
onError: (id, error) => {
console.error(`Message ${id} failed:`, error);
statusCallback?.onError?.(id, error);
}
});
return messageId;
}
await this.reliableMessaging.sendMessage(message, {
onSent: (id) => {
console.log(`Message ${id} sent`);
statusCallback?.onSent?.(id);
},
onAcknowledged: (id) => {
console.log(`Message ${id} acknowledged`);
statusCallback?.onAcknowledged?.(id);
},
onError: (id, error) => {
console.error(`Message ${id} failed:`, error);
statusCallback?.onError?.(id, error);
}
});
}
public onMessageReceived(callback: MessageReceivedCallback): () => void {
this.messageReceivedCallbacks.add(callback);