debounced 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f40aa8391039a8a5639ba8e5b77c64d38a07c0208eb158939df97770ae40b240
4
- data.tar.gz: 05c33de396be8333e1945880ee7518b67d361d23aa01f68936a4740e6776acee
3
+ metadata.gz: c9fa1cd41e5d203718e5f338068db77acd8b07f15369c705e096f9a2108b7614
4
+ data.tar.gz: 544067be17e4efad251d656374b5d41a08c2c3ad627fc7f0ac75dbdf83be0c05
5
5
  SHA512:
6
- metadata.gz: b3b7aa2939222ef134b925b70a7d9bb4e535876bd317901cb3d022c880f5c397d2fc4b2a9666db9674ca1e1a6112761da664fdc4c2841f157c38010c4de929e9
7
- data.tar.gz: 2dc3ae74b658a1ab57bbabd8cef240629102700d49a7980ddd7694c458af36dd7c91e7a55e472a75acdf2188eab511c2612dc6a8f215d3124b08a711e685ae2c
6
+ metadata.gz: 7965f45c4e5055cf0c0e98123c6e88b5e7f1d9ef2ac6e0ecc1a3f09e51364b6feb2d5c3f07dc294d54a6f15af717cf6b6ccb87eae090466583f07f8ff6d162cd
7
+ data.tar.gz: 7165afce55d82ff97a1747181bd219e63a94ac79f23d0ec3b3ffbc04b4c6ce31f83be4b1a3372dd20484bae19db00f4546e7e4bc02f162efaf5dc560c4569fae
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Fixed
11
+
12
+ - Each process's descriptors are debounced separately. When two processes debounced the same descriptor, the later
13
+ request cancelled the earlier process's callback; now each process gets its own callback, and a process's pending
14
+ callbacks are cancelled when it disconnects
15
+
16
+ ## [2.1.0] - 2026-09-26
17
+
10
18
  ### Security
11
19
 
12
20
  - Callbacks are only dispatched to public methods defined by the application, never to core Ruby methods
@@ -9,8 +9,7 @@ function log(message, ...args) {
9
9
  export default class DebounceService {
10
10
  constructor(socketDescriptor) {
11
11
  this._socketDescriptor = socketDescriptor;
12
- this._timers = {};
13
- this._clients = new Set();
12
+ this._timers = new Map();
14
13
  this.publishEvent = this.publishEvent.bind(this);
15
14
  this.debounceEvent = this.debounceEvent.bind(this);
16
15
  this.reset = this.reset.bind(this);
@@ -29,7 +28,8 @@ export default class DebounceService {
29
28
 
30
29
  onClientDisconnected(socket) {
31
30
  log('DebounceService client disconnected');
32
- this._clients.delete(socket);
31
+ this._timers.get(socket).forEach(timerID => clearTimeout(timerID));
32
+ this._timers.delete(socket);
33
33
  }
34
34
 
35
35
  handleMessage(message, socket) {
@@ -50,7 +50,7 @@ export default class DebounceService {
50
50
  onClientConnected(socket) {
51
51
  log('DebounceService client connected');
52
52
  let connectionBuffer = '';
53
- this._clients.add(socket);
53
+ this._timers.set(socket, new Map());
54
54
  socket.on('close', () => this.onClientDisconnected(socket));
55
55
  socket.on('error', this.onConnectionError);
56
56
  socket.setEncoding('utf8');
@@ -135,11 +135,6 @@ export default class DebounceService {
135
135
  }
136
136
 
137
137
  publishEvent(descriptor, callback, socket) {
138
- if (!this._clients.has(socket)) {
139
- log(`Debounce period expired for ${descriptor} - client disconnected, dropping`);
140
- return;
141
- }
142
-
143
138
  log(`Debounce period expired for ${descriptor} - sending to client`);
144
139
  const message = JSON.stringify({
145
140
  type: 'publishEvent',
@@ -149,20 +144,21 @@ export default class DebounceService {
149
144
  }
150
145
 
151
146
  debounceEvent({ descriptor, timeout, callback }, socket) {
152
- if (this._timers[descriptor]) {
153
- clearTimeout(this._timers[descriptor]);
154
- }
147
+ const timers = this._timers.get(socket);
148
+ clearTimeout(timers.get(descriptor));
155
149
 
156
150
  log("Debouncing", descriptor);
157
- this._timers[descriptor] = setTimeout(() => {
158
- delete this._timers[descriptor];
151
+ timers.set(descriptor, setTimeout(() => {
152
+ timers.delete(descriptor);
159
153
  this.publishEvent(descriptor, callback, socket);
160
- }, timeout * 1000);
154
+ }, timeout * 1000));
161
155
  }
162
156
 
163
157
  reset() {
164
- Object.values(this._timers).forEach(timerID => clearTimeout(timerID));
165
- this._timers = {};
158
+ this._timers.forEach(timers => {
159
+ timers.forEach(timerID => clearTimeout(timerID));
160
+ timers.clear();
161
+ });
166
162
  }
167
163
 
168
164
  handleError(err) {
@@ -1,3 +1,3 @@
1
1
  module Debounced
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debounced
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero