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,10 +10,12 @@ export class BatchTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public queue(id: string, timeout: number){
|
public queue(id: string, timeout: number){
|
||||||
|
if (!this._batch.includes(id)) {
|
||||||
this._timer = new Date().getTime() + timeout;
|
this._timer = new Date().getTime() + timeout;
|
||||||
this._batch.push(id);
|
this._batch.push(id);
|
||||||
setTimeout(this.checkBatch.bind(this), timeout);
|
setTimeout(this.checkBatch.bind(this), timeout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private checkBatch() {
|
private checkBatch() {
|
||||||
if ((new Date()).getTime() >= this._timer) {
|
if ((new Date()).getTime() >= this._timer) {
|
||||||
|
|
|
@ -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