mirror of
				https://github.com/Yidadaa/ChatGPT-Next-Web.git
				synced 2025-11-04 16:57:27 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			914 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			914 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
// To store message streaming controller
 | 
						|
export const ChatControllerPool = {
 | 
						|
  controllers: {} as Record<string, AbortController>,
 | 
						|
 | 
						|
  addController(
 | 
						|
    sessionId: string,
 | 
						|
    messageId: string,
 | 
						|
    controller: AbortController,
 | 
						|
  ) {
 | 
						|
    const key = this.key(sessionId, messageId);
 | 
						|
    this.controllers[key] = controller;
 | 
						|
    return key;
 | 
						|
  },
 | 
						|
 | 
						|
  stop(sessionId: string, messageId: string) {
 | 
						|
    const key = this.key(sessionId, messageId);
 | 
						|
    const controller = this.controllers[key];
 | 
						|
    controller?.abort();
 | 
						|
  },
 | 
						|
 | 
						|
  stopAll() {
 | 
						|
    Object.values(this.controllers).forEach((v) => v.abort());
 | 
						|
  },
 | 
						|
 | 
						|
  hasPending() {
 | 
						|
    return Object.values(this.controllers).length > 0;
 | 
						|
  },
 | 
						|
 | 
						|
  remove(sessionId: string, messageId: string) {
 | 
						|
    const key = this.key(sessionId, messageId);
 | 
						|
    delete this.controllers[key];
 | 
						|
  },
 | 
						|
 | 
						|
  key(sessionId: string, messageIndex: string) {
 | 
						|
    return `${sessionId},${messageIndex}`;
 | 
						|
  },
 | 
						|
};
 |