Update stream.ts

This commit is contained in:
L̷O̷N̷D̷O̷N̷少林 2025-01-15 11:25:48 -05:00 committed by GitHub
parent 55b3f22dc3
commit 4b19cff643
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,14 +72,14 @@ export default class Stream extends EventEmitter {
this.state = 'connected'; this.state = 'connected';
this.emit('_connected_'); this.emit('_connected_');
// バッファーを処理 // Process the buffer
const _buffer = [...this.buffer]; // Shallow copy const _buffer = [...this.buffer]; // Shallow copy
this.buffer = []; // Clear buffer this.buffer = []; // Clear buffer
for (const data of _buffer) { for (const data of _buffer) {
this.send(data); // Resend each buffered messages this.send(data); // Resend each buffered messages
} }
// チャンネル再接続 // Reconnect the channel
if (isReconnect) { if (isReconnect) {
this.sharedConnectionPools.forEach(p => { this.sharedConnectionPools.forEach(p => {
p.connect(); p.connect();
@ -137,7 +137,7 @@ export default class Stream extends EventEmitter {
body: payload body: payload
}; };
// まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する // If the connection is not established yet, buffer it and send it the next time a connection is established.
if (this.state != 'connected') { if (this.state != 'connected') {
this.buffer.push(data); this.buffer.push(data);
return; return;
@ -179,7 +179,7 @@ class Pool {
this.users++; this.users++;
// タイマー解除 // Cancel the timer
if (this.disposeTimerId) { if (this.disposeTimerId) {
clearTimeout(this.disposeTimerId); clearTimeout(this.disposeTimerId);
this.disposeTimerId = null; this.disposeTimerId = null;
@ -192,8 +192,7 @@ class Pool {
// そのコネクションの利用者が誰もいなくなったら // そのコネクションの利用者が誰もいなくなったら
if (this.users === 0) { if (this.users === 0) {
// また直ぐに再利用される可能性があるので、一定時間待ち、 // Since there is a possibility that the connection will be reused soon, wait a certain amount of time, and if no new users appear, close the connection.
// 新たな利用者が現れなければコネクションを切断する
this.disposeTimerId = setTimeout(() => { this.disposeTimerId = setTimeout(() => {
this.disconnect(); this.disconnect();
}, 3000); }, 3000);