@hardlydifficult/poller 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/README.md +25 -33
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @hardlydifficult/poller
2
2
 
3
- Polls an async function at a configurable interval and triggers callbacks when the result changes.
3
+ Polls async functions at configurable intervals and triggers callbacks only when the result changes—using deep equality detection via JSON serialization.
4
4
 
5
5
  ## Install
6
6
 
@@ -30,7 +30,7 @@ poller.stop();
30
30
 
31
31
  ## Polling
32
32
 
33
- The `Poller` class periodically fetches data and invokes a callback when the result changes. It fetches immediately on `start()`, then at the configured interval.
33
+ The `Poller` class fetches data at a configurable interval and invokes a callback when the result changes. It fetches immediately on `start()`, then at the configured interval.
34
34
 
35
35
  ```typescript
36
36
  import { Poller } from "@hardlydifficult/poller";
@@ -51,9 +51,27 @@ await poller.start();
51
51
  // Fetches immediately, then every 10 seconds
52
52
  ```
53
53
 
54
+ ### start()
55
+
56
+ Starts polling. Fetches immediately, then at the configured interval. Calling `start()` multiple times is safe (idempotent).
57
+
58
+ ```typescript
59
+ await poller.start(); // Fetches immediately
60
+ await poller.start(); // No-op, already running
61
+ ```
62
+
63
+ ### stop()
64
+
65
+ Stops polling and cleans up all timers.
66
+
67
+ ```typescript
68
+ poller.stop();
69
+ // No more polls will fire
70
+ ```
71
+
54
72
  ## Change Detection
55
73
 
56
- Changes are detected using JSON serialization for deep equality. Structurally identical objects are considered unchanged, even if they are different references.
74
+ Changes are detected using JSON serialization for deep equality. Structurally identical objects are considered unchangedeven if they are different references.
57
75
 
58
76
  ```typescript
59
77
  const poller = new Poller(
@@ -111,32 +129,6 @@ const poller = new Poller(
111
129
  await poller.start();
112
130
  ```
113
131
 
114
- ## Lifecycle
115
-
116
- ### `start()`
117
-
118
- Starts polling. Fetches immediately, then at the configured interval. Calling `start()` multiple times is safe (idempotent).
119
-
120
- ```typescript
121
- const poller = new Poller(
122
- async () => await fetchData(),
123
- (current) => console.log("Updated:", current),
124
- 5000
125
- );
126
-
127
- await poller.start(); // Fetches immediately
128
- await poller.start(); // No-op, already running
129
- ```
130
-
131
- ### `stop()`
132
-
133
- Stops polling and cleans up all timers.
134
-
135
- ```typescript
136
- poller.stop();
137
- // No more polls will fire
138
- ```
139
-
140
132
  ## API Reference
141
133
 
142
134
  ### Constructor
@@ -151,7 +143,7 @@ new Poller<T>(
151
143
  ```
152
144
 
153
145
  | Parameter | Description |
154
- |-----------|-------------|
146
+ |---|---|
155
147
  | `fetchFn` | Async function that returns the current state |
156
148
  | `onChange` | Called with `(current, previous)` when state changes |
157
149
  | `intervalMs` | Polling interval in milliseconds |
@@ -160,14 +152,14 @@ new Poller<T>(
160
152
  ### Methods
161
153
 
162
154
  | Method | Description |
163
- |--------|-------------|
155
+ |---|---|
164
156
  | `start()` | Start polling (fetches immediately, then at interval) |
165
157
  | `stop()` | Stop polling and clean up timers |
166
- | `trigger(debounceMs?)` | Manually trigger a poll with debounce (default 1000ms) |
158
+ | `trigger(debounceMs?)` | Manually trigger a poll with debounce (default `1000`ms) |
167
159
 
168
160
  ### Behavior
169
161
 
170
- - **Deep equality** — uses JSON serialization to detect changes
162
+ - **Deep equality** — uses JSON serialization to detect structural changes
171
163
  - **Overlap prevention** — skips a poll if the previous fetch is still running
172
164
  - **Error resilience** — continues polling after fetch errors
173
165
  - **Idempotent start** — calling `start()` multiple times is safe
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardlydifficult/poller",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [