don't add redundant IDs to batch timers, close data channel properly
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZsfqnQAKCRBohAcXSWbK 832pAP4yzlMYKwh/UvOR37ffZ/2FczVnErgBHUd4N846BJqhHwD9G1RS6+KpJFTS Z94xRXr5q59Q+Tq2861C9XzzSstNSAI= =TQKQ -----END PGP SIGNATURE-----
2 files changed,
8 insertions(+),
3 deletions(-)
M
frontend/ts/batch-timer.ts
→
frontend/ts/batch-timer.ts
@@ -10,9 +10,11 @@ this._reqFn = reqFn;
} public queue(id: string, timeout: number){ - this._timer = new Date().getTime() + timeout; - this._batch.push(id); - setTimeout(this.checkBatch.bind(this), timeout); + if (!this._batch.includes(id)) { + this._timer = new Date().getTime() + timeout; + this._batch.push(id); + setTimeout(this.checkBatch.bind(this), timeout); + } } private checkBatch() {
M
server/server.go
→
server/server.go
@@ -98,6 +98,7 @@ writeTimeout(ctx, time.Second*5, c, msg)
case <-ctx.Done(): fmt.Println("subscriber has disconnected") + close(s.data) return //ctx.Err() } }@@ -108,6 +109,8 @@ s.msgs <- []byte("{ \"key\":\"" + s.key + "\" }")
// block on the data channel, serializing and passing the data to the subscriber listen([]chan models.SocketData{s.data}, s.msgs) + + fmt.Println("data listener is done!") if errors.Is(err, context.Canceled) { return