don't add redundant IDs to batch timers, close data channel properly
This commit is contained in:
parent
bb7d4e2f7d
commit
7a2eb99eb6
2 changed files with 8 additions and 3 deletions
|
@ -10,9 +10,11 @@ export class BatchTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public queue(id: string, timeout: number){
|
public queue(id: string, timeout: number){
|
||||||
this._timer = new Date().getTime() + timeout;
|
if (!this._batch.includes(id)) {
|
||||||
this._batch.push(id);
|
this._timer = new Date().getTime() + timeout;
|
||||||
setTimeout(this.checkBatch.bind(this), timeout);
|
this._batch.push(id);
|
||||||
|
setTimeout(this.checkBatch.bind(this), timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkBatch() {
|
private checkBatch() {
|
||||||
|
|
|
@ -98,6 +98,7 @@ func (self *BBSServer) subscribeHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
fmt.Println("subscriber has disconnected")
|
fmt.Println("subscriber has disconnected")
|
||||||
|
close(s.data)
|
||||||
return //ctx.Err()
|
return //ctx.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +110,8 @@ func (self *BBSServer) subscribeHandler(w http.ResponseWriter, r *http.Request)
|
||||||
// block on the data channel, serializing and passing the data to the subscriber
|
// block on the data channel, serializing and passing the data to the subscriber
|
||||||
listen([]chan models.SocketData{s.data}, s.msgs)
|
listen([]chan models.SocketData{s.data}, s.msgs)
|
||||||
|
|
||||||
|
fmt.Println("data listener is done!")
|
||||||
|
|
||||||
if errors.Is(err, context.Canceled) {
|
if errors.Is(err, context.Canceled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue