Skip to content

Commit

Permalink
fix: ReceiptManager shared singleton cyclic dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ieddcn authored and tangtaoit committed Dec 11, 2024
1 parent 95887e5 commit e344598
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class WKSDK {
this.conversationManager = ConversationManager.shared()
this.securityManager = SecurityManager.shared()
this.reminderManager = ReminderManager.shared()
this.receiptManager = ReceiptManager.shared()
this.receiptManager = ReceiptManager.shared(this.config.receiptFlushInterval)


this.registerFactor((contentType: number): MessageContent | undefined => {
Expand Down
10 changes: 5 additions & 5 deletions src/receipt_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ export type MessageReceiptListener = ((channel:Channel,message: Message[]) => vo
export class ReceiptManager {
private static instance: ReceiptManager
listeners: MessageReceiptListener[] = new Array(); // 回执监听
private timer!:NodeJS.Timeout
public static shared() {
private timer!:NodeJS.Timeout | null | number
public static shared(flushInterval:number = 2000) {
if (!this.instance) {
this.instance = new ReceiptManager();
this.instance.setup()
this.instance.setup(flushInterval)
}
return this.instance;
}

private channelMessagesMap = new Map<string,Message[]>();

private setup() {
this.timer = setInterval(this.flushLoop.bind(this),WKSDK.shared().config.receiptFlushInterval)
private setup(flushInterval:number) {
this.timer = setInterval(this.flushLoop.bind(this),flushInterval)
}

// 添加需要回执的消息
Expand Down

0 comments on commit e344598

Please sign in to comment.