rxjs-poll 2.2.2 → 2.2.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 (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +263 -263
  3. package/dist/cjs/index.js +134 -78
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/esm/index.js +135 -79
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/types/common/service.d.ts +9 -0
  8. package/dist/types/common/service.d.ts.map +1 -0
  9. package/dist/types/constants/config.const.d.ts +1 -1
  10. package/dist/types/constants/state.const.d.ts +8 -0
  11. package/dist/types/constants/state.const.d.ts.map +1 -0
  12. package/dist/types/constants/timing.const.d.ts +6 -0
  13. package/dist/types/constants/timing.const.d.ts.map +1 -0
  14. package/dist/types/observables/factory.d.ts +11 -0
  15. package/dist/types/observables/factory.d.ts.map +1 -0
  16. package/dist/types/observables/interval-poller.d.ts +3 -3
  17. package/dist/types/observables/interval-poller.d.ts.map +1 -1
  18. package/dist/types/observables/pause-delay.d.ts +7 -0
  19. package/dist/types/observables/pause-delay.d.ts.map +1 -0
  20. package/dist/types/observables/repeat-poller.d.ts +3 -3
  21. package/dist/types/observables/repeat-poller.d.ts.map +1 -1
  22. package/dist/types/operators/retry-pol.operator.d.ts +11 -0
  23. package/dist/types/operators/retry-pol.operator.d.ts.map +1 -0
  24. package/dist/types/poll.d.ts +1 -1
  25. package/dist/types/poll.d.ts.map +1 -1
  26. package/dist/types/types/config.type.d.ts +1 -1
  27. package/dist/types/types/observables.type.d.ts +9 -21
  28. package/dist/types/types/observables.type.d.ts.map +1 -1
  29. package/dist/types/types/poll.type.d.ts +1 -6
  30. package/dist/types/types/poll.type.d.ts.map +1 -1
  31. package/dist/types/types/retry.type.d.ts +7 -0
  32. package/dist/types/types/retry.type.d.ts.map +1 -0
  33. package/dist/types/types/service.type.d.ts +18 -0
  34. package/dist/types/types/service.type.d.ts.map +1 -0
  35. package/dist/umd/index.js +134 -78
  36. package/dist/umd/index.js.map +1 -1
  37. package/dist/umd/index.min.js +1 -1
  38. package/dist/umd/index.min.js.map +1 -1
  39. package/package.json +5 -5
  40. package/dist/types/common/state.d.ts +0 -8
  41. package/dist/types/common/state.d.ts.map +0 -1
  42. package/dist/types/observables/poller-factory.d.ts +0 -11
  43. package/dist/types/observables/poller-factory.d.ts.map +0 -1
  44. package/dist/types/observables/retry-operator.d.ts +0 -11
  45. package/dist/types/observables/retry-operator.d.ts.map +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Marin Muštra
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Marin Muštra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,263 +1,263 @@
1
- # RxJS Polling Operator
2
-
3
- <a href="https://www.npmjs.com/package/rxjs-poll" target="_blank" rel="noopener noreferrer nofollow"><img alt="NPM Version" src="https://img.shields.io/npm/v/rxjs-poll"></a>
4
- <a href="https://bundlephobia.com/package/rxjs-poll@latest" target="_blank" rel="noopener noreferrer nofollow"><img alt="NPM Bundle Size" src="https://img.shields.io/bundlephobia/minzip/rxjs-poll/latest?label=gzip"></a>
5
- <a href="LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub License" src="https://img.shields.io/github/license/mmustra/rxjs-poll"></a>
6
- <a href="https://github.com/mmustra/rxjs-poll/tree/main/tests" target="_blank" rel="noopener noreferrer nofollow"><img alt="Codecov" src="https://img.shields.io/codecov/c/gh/mmustra/rxjs-poll?token=H9R97BLFQI"></a>
7
- <a href="https://github.com/mmustra/rxjs-poll/issues?q=is%3Aissue%20state%3Aopen%20label%3Alatest" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub Issues" src="https://img.shields.io/github/issues/mmustra/rxjs-poll/latest?label=issues"></a>
8
- <a href="https://github.com/mmustra/rxjs-poll/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub Latest Commits" src="https://img.shields.io/github/last-commit/mmustra/rxjs-poll/main?label=activity"></a>
9
-
10
- A flexible RxJS operator library that enables polling on any completed observable source with advanced timing and retry strategies.
11
-
12
- ## 🚀 Features
13
-
14
- - **Two polling types**: `repeat` and `interval` to suit different use cases
15
- - **Timing strategies**: `constant`, `linear`, `exponential`, `random` and `dynamic` (custom logic)
16
- - **Auto-pause**: Automatically pause/resume polling based on page visibility (browser only)
17
- - **Flexible retries**: Control retry attempts with consecutive or total counting modes
18
- - **Input validation**: Guards against unexpected input time values
19
- - **Cross-platform**: Works in both browser and Node.js environments
20
- - **Modern compatibility**: Compatible with RxJS v7+
21
- - **Multiple module formats**: Supports CJS, ESM, and UMD
22
-
23
- ## 📦 Installation
24
-
25
- ```shell
26
- npm install rxjs-poll --save
27
- ```
28
-
29
- ## 🎯 Purpose & Process
30
-
31
- Polling is essential when you need to repeatedly check for updates from sources that don't provide real-time notifications. Common scenarios include monitoring HTTP API endpoints for status changes, watching DOM elements for state updates, or periodically sampling data streams.
32
-
33
- This operator cleanly separates polling concerns from your core observable logic. It waits for your source observable to complete per polling type, then schedules the next poll based on your configuration. The architecture distinguishes between normal polling delays and error retry scenarios, giving you precise control over both success and failure timing strategies.
34
-
35
- ## 📚 Usage Examples
36
-
37
- ### Default Configuration
38
-
39
- [▶️ Live Demo](https://stackblitz.com/edit/rxjs-xdf2x4vx?devToolsHeight=100&file=index.ts)
40
-
41
- Plug and play - just add the operator to your pipe and start polling.
42
-
43
- ```typescript
44
- import { poll } from 'rxjs-poll';
45
- import { takeWhile } from 'rxjs';
46
-
47
- request$
48
- .pipe(
49
- poll(), // Poll every second with exponential retry strategy (7s max)
50
- takeWhile(({ status }) => status !== 'done', true)
51
- )
52
- .subscribe({ next: console.log });
53
- ```
54
-
55
- ### Strategy-Based Configuration
56
-
57
- [▶️ Live Demo](https://stackblitz.com/edit/rxjs-vrefdzj1?devToolsHeight=100&file=index.ts)
58
-
59
- Use built-in strategies for easy timing control.
60
-
61
- ```typescript
62
- import { poll } from 'rxjs-poll';
63
- import { takeWhile } from 'rxjs';
64
-
65
- request$
66
- .pipe(
67
- poll({
68
- type: 'interval', // Drops uncompleted source after delay
69
- delay: {
70
- strategy: 'random',
71
- time: [1000, 3000], // Random delay between 1 and 3 seconds
72
- },
73
- retry: {
74
- limit: Infinity, // Will never throw
75
- },
76
- }),
77
- takeWhile(({ status }) => status !== 'done', true)
78
- )
79
- .subscribe({ next: console.log });
80
- ```
81
-
82
- ### Advanced Dynamic Strategies
83
-
84
- [▶️ Live Demo](https://stackblitz.com/edit/rxjs-6fmgfij8?devtoolsheight=100&file=index.ts)
85
-
86
- Implement complex polling strategies with dynamic timing based on poll state.
87
-
88
- ```typescript
89
- import { poll } from 'rxjs-poll';
90
- import { takeWhile } from 'rxjs';
91
-
92
- request$
93
- .pipe(
94
- poll({
95
- delay: {
96
- /** Adaptive polling based on response data */
97
- strategy: 'dynamic',
98
- time: ({ value }) => (value?.items.length ? 1000 : 500),
99
- },
100
- retry: {
101
- /** Custom exponential backoff with jitter */
102
- strategy: 'dynamic',
103
- time: ({ consecutiveRetryCount }) => {
104
- const exponential = Math.pow(2, consecutiveRetryCount - 1) * 1000;
105
- const jitter = Math.random() * 200;
106
-
107
- return exponential + jitter;
108
- },
109
- limit: 6,
110
- },
111
- }),
112
- takeWhile(({ status }) => status !== 'done', true)
113
- )
114
- .subscribe({ next: console.log });
115
- ```
116
-
117
- ## 📋 API Reference
118
-
119
- ### `poll(config?: PollConfig)`
120
-
121
- Creates a polling operator that will begin polling once the source observable completes.
122
-
123
- #### PollConfig
124
-
125
- ```typescript
126
- interface PollConfig {
127
- /**
128
- * Defines the polling behavior:
129
- * - 'repeat': Polls after current source completes
130
- * - 'interval': Polls in intervals, dropping any ongoing source operations
131
- * @default 'repeat'
132
- */
133
- type?: 'repeat' | 'interval';
134
-
135
- /**
136
- * Configuration for polling delays (between successful operations)
137
- */
138
- delay?: {
139
- /**
140
- * Strategy type for delay timing. Built-in strategies (except dynamic)
141
- * calculate time per state's `pollCount`.
142
- * @default 'constant'
143
- */
144
- strategy: 'constant' | 'linear' | 'exponential' | 'random' | 'dynamic';
145
-
146
- /**
147
- * Time (ms) depending on strategy:
148
- * - constant: number
149
- * - linear: number
150
- * - exponential: number
151
- * - random: [min, max]
152
- * - dynamic: (state) => number | [min, max]
153
- * @default 1000
154
- */
155
- time:
156
- | number
157
- | [min: number, max: number]
158
- | (state: PollState) => number | [min: number, max: number];
159
- };
160
-
161
- /**
162
- * Configuration for retry behavior (on errors)
163
- */
164
- retry?: {
165
- /**
166
- * Strategy type for retry timing. Built-in strategies (except dynamic)
167
- * calculate time per state:
168
- * - consecutiveOnly: true → uses `consecutiveRetryCount`
169
- * - consecutiveOnly: false → uses `retryCount`
170
- * @default 'exponential'
171
- * @note Required if `time` is provided, otherwise uses default
172
- */
173
- strategy: 'constant' | 'linear' | 'exponential' | 'random' | 'dynamic';
174
-
175
- /**
176
- * Time (ms) depending on strategy:
177
- * - constant: number
178
- * - linear: number
179
- * - exponential: number
180
- * - random: [min, max]
181
- * - dynamic: (state) => number | [min, max]
182
- * @default 1000
183
- * @note Required if `strategy` is provided, otherwise uses default
184
- */
185
- time:
186
- | number
187
- | [min: number, max: number]
188
- | (state: PollState) => number | [min: number, max: number];
189
-
190
- /**
191
- * Maximum number of retry attempts before throwing an error.
192
- * Use `Infinity` to keep retrying indefinitely.
193
- * @default 3
194
- */
195
- limit?: number;
196
-
197
- /**
198
- * Controls how retries are counted:
199
- * - true: Only consecutive errors count toward retry limit
200
- * (resets counter on success)
201
- * - false: All errors count toward retry limit regardless of
202
- * successful responses between them
203
- * @default true
204
- */
205
- consecutiveOnly?: boolean;
206
- };
207
-
208
- /**
209
- * [Browser only] Controls polling behavior when page isn't visible
210
- * - true: Pause polling when tab isn't active, and resume on active
211
- * - false: Poll even when tab isn't focused
212
- * @default true
213
- * @note Every started cycle finishes before pausing
214
- */
215
- pauseWhenHidden?: boolean;
216
- }
217
- ```
218
-
219
- ### PollState
220
-
221
- State object passed to delay/retry time producer functions:
222
-
223
- ```typescript
224
- interface PollState<T> {
225
- /** Latest value from the source. For `interval` polling type,
226
- * first emission is undefined. */
227
- value: T | undefined;
228
-
229
- /** Latest error when retrying */
230
- error: any | undefined;
231
-
232
- /** Total number of successful poll operations */
233
- pollCount: number;
234
-
235
- /** Total number of retry attempts */
236
- retryCount: number;
237
-
238
- /** Current number of consecutive retry attempts */
239
- consecutiveRetryCount: number;
240
- }
241
-
242
- /** Note: pollCount + retryCount = total attempts */
243
- ```
244
-
245
- ## 🚨 Breaking Changes
246
-
247
- **Version 2** ([source](https://github.com/mmustra/rxjs-poll)) introduces an API focused on strategy-based configuration with improved type safety and clearer separation between polling delays and retry behavior. See [V2 Changes](docs/V2_CHANGES.md) for detailed migration guide and examples.
248
-
249
- **Version 1** ([source](https://github.com/mmustra/rxjs-poll/tree/v1)) will continue to receive bug fixes and security updates.
250
-
251
- ## 🤝 Contributing
252
-
253
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
254
-
255
- Have a question? Check out [GitHub Discussions](https://github.com/mmustra/rxjs-poll/discussions) to ask questions, share ideas, or get help from the community.
256
-
257
- ## 🙌 Credits
258
-
259
- This library is inspired by [rx-polling](https://github.com/jiayihu/rx-polling), which creates an Observable for polling.
260
-
261
- ## 📄 License
262
-
263
- [MIT](LICENSE)
1
+ # RxJS Polling Operator
2
+
3
+ <a href="https://www.npmjs.com/package/rxjs-poll" target="_blank" rel="noopener noreferrer nofollow"><img alt="NPM Version" src="https://img.shields.io/npm/v/rxjs-poll"></a>
4
+ <a href="https://bundlephobia.com/package/rxjs-poll@latest" target="_blank" rel="noopener noreferrer nofollow"><img alt="NPM Bundle Size" src="https://img.shields.io/bundlephobia/minzip/rxjs-poll/latest?label=gzip"></a>
5
+ <a href="LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub License" src="https://img.shields.io/github/license/mmustra/rxjs-poll"></a>
6
+ <a href="https://github.com/mmustra/rxjs-poll/tree/main/tests" target="_blank" rel="noopener noreferrer nofollow"><img alt="Codecov" src="https://img.shields.io/codecov/c/gh/mmustra/rxjs-poll?token=H9R97BLFQI"></a>
7
+ <a href="https://github.com/mmustra/rxjs-poll/issues?q=is%3Aissue%20state%3Aopen%20label%3Alatest" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub Issues" src="https://img.shields.io/github/issues/mmustra/rxjs-poll/latest?label=issues"></a>
8
+ <a href="https://github.com/mmustra/rxjs-poll/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img alt="GitHub Latest Commits" src="https://img.shields.io/github/last-commit/mmustra/rxjs-poll/main?label=activity"></a>
9
+
10
+ A flexible RxJS operator library that enables polling on any completed observable source with advanced timing and retry strategies.
11
+
12
+ ## 🚀 Features
13
+
14
+ - **Two polling types**: `repeat` and `interval` to suit different use cases
15
+ - **Timing strategies**: `constant`, `linear`, `exponential`, `random` and `dynamic` (custom logic)
16
+ - **Auto-pause**: Automatically pause/resume polling based on page visibility (browser only)
17
+ - **Reliable execution**: First and in-flight cycles (poll or retry) guaranteed
18
+ - **Flexible retries**: Control retry attempts with consecutive or total counting modes
19
+ - **Input validation**: Guards against unexpected input time values
20
+ - **Cross-platform**: Works in both browser and Node.js environments
21
+ - **Modern compatibility**: Compatible with RxJS v7+
22
+ - **Module formats**: Supports CJS, ESM, and UMD
23
+
24
+ ## 📦 Installation
25
+
26
+ ```shell
27
+ npm install rxjs-poll --save
28
+ ```
29
+
30
+ ## 🎯 Purpose & Process
31
+
32
+ Polling is essential when you need to repeatedly check for updates from sources that don't provide real-time notifications. Common scenarios include monitoring HTTP API endpoints for status changes, watching DOM elements for state updates, or periodically sampling data streams.
33
+
34
+ This operator cleanly separates polling concerns from your core observable logic. It waits for your source observable to complete per polling type, then schedules the next poll based on your configuration. The architecture distinguishes between normal polling delays and error retry scenarios, giving you precise control over both success and failure timing strategies.
35
+
36
+ ## 🧪 Usage Examples
37
+
38
+ ### Default Configuration
39
+
40
+ [▶️ Live Demo](https://stackblitz.com/edit/rxjs-xdf2x4vx?devToolsHeight=100&file=index.ts)
41
+
42
+ Plug and play - just add the operator to your pipe and start polling.
43
+
44
+ ```typescript
45
+ import { poll } from 'rxjs-poll';
46
+ import { takeWhile } from 'rxjs';
47
+
48
+ request$
49
+ .pipe(
50
+ poll(), // Poll every second with exponential retry strategy (7s max)
51
+ takeWhile(({ status }) => status !== 'done', true)
52
+ )
53
+ .subscribe({ next: console.log });
54
+ ```
55
+
56
+ ### Strategy-Based Configuration
57
+
58
+ [▶️ Live Demo](https://stackblitz.com/edit/rxjs-vrefdzj1?devToolsHeight=100&file=index.ts)
59
+
60
+ Use built-in strategies for easy timing control.
61
+
62
+ ```typescript
63
+ import { poll } from 'rxjs-poll';
64
+ import { takeWhile } from 'rxjs';
65
+
66
+ request$
67
+ .pipe(
68
+ poll({
69
+ type: 'interval', // Drops uncompleted source after delay
70
+ delay: {
71
+ strategy: 'random',
72
+ time: [1000, 3000], // Random delay between 1 and 3 seconds
73
+ },
74
+ retry: {
75
+ limit: Infinity, // Will never throw
76
+ },
77
+ }),
78
+ takeWhile(({ status }) => status !== 'done', true)
79
+ )
80
+ .subscribe({ next: console.log });
81
+ ```
82
+
83
+ ### Advanced Dynamic Strategies
84
+
85
+ [▶️ Live Demo](https://stackblitz.com/edit/rxjs-6fmgfij8?devToolsHeight=100&file=index.ts)
86
+
87
+ Implement complex polling strategies with dynamic timing based on poll state.
88
+
89
+ ```typescript
90
+ import { poll } from 'rxjs-poll';
91
+ import { takeWhile } from 'rxjs';
92
+
93
+ request$
94
+ .pipe(
95
+ poll({
96
+ delay: {
97
+ /** Adaptive polling based on response data */
98
+ strategy: 'dynamic',
99
+ time: ({ value }) => (value?.items.length ? 1000 : 500),
100
+ },
101
+ retry: {
102
+ /** Custom exponential backoff with jitter */
103
+ strategy: 'dynamic',
104
+ time: ({ consecutiveRetryCount }) => {
105
+ const exponential = Math.pow(2, consecutiveRetryCount - 1) * 1000;
106
+ const jitter = Math.random() * 200;
107
+
108
+ return exponential + jitter;
109
+ },
110
+ limit: 6,
111
+ },
112
+ }),
113
+ takeWhile(({ status }) => status !== 'done', true)
114
+ )
115
+ .subscribe({ next: console.log });
116
+ ```
117
+
118
+ ## 📋 API Reference
119
+
120
+ ### `poll(config?: PollConfig)`
121
+
122
+ Creates a polling operator that will begin polling once the source observable completes.
123
+
124
+ #### PollConfig
125
+
126
+ ```typescript
127
+ interface PollConfig {
128
+ /**
129
+ * Defines the polling behavior:
130
+ * - 'repeat': Polls after current source completes
131
+ * - 'interval': Polls in intervals, dropping any ongoing source operations
132
+ * @default 'repeat'
133
+ */
134
+ type?: 'repeat' | 'interval';
135
+
136
+ /**
137
+ * Configuration for polling delays (between successful operations)
138
+ */
139
+ delay?: {
140
+ /**
141
+ * Strategy type for delay timing. Built-in strategies (except dynamic)
142
+ * calculate time per state's `pollCount`.
143
+ * @default 'constant'
144
+ */
145
+ strategy: 'constant' | 'linear' | 'exponential' | 'random' | 'dynamic';
146
+
147
+ /**
148
+ * Time (ms) depending on strategy:
149
+ * - constant: number
150
+ * - linear: number
151
+ * - exponential: number
152
+ * - random: [min, max]
153
+ * - dynamic: (state) => number | [min, max]
154
+ * @default 1000
155
+ */
156
+ time:
157
+ | number
158
+ | [min: number, max: number]
159
+ | (state: PollState) => number | [min: number, max: number];
160
+ };
161
+
162
+ /**
163
+ * Configuration for retry behavior (on errors)
164
+ */
165
+ retry?: {
166
+ /**
167
+ * Strategy type for retry timing. Built-in strategies (except dynamic)
168
+ * calculate time per state:
169
+ * - consecutiveOnly: true → uses `consecutiveRetryCount`
170
+ * - consecutiveOnly: false → uses `retryCount`
171
+ * @default 'exponential'
172
+ * @note Required if `time` is provided, otherwise uses default
173
+ */
174
+ strategy: 'constant' | 'linear' | 'exponential' | 'random' | 'dynamic';
175
+
176
+ /**
177
+ * Time (ms) depending on strategy:
178
+ * - constant: number
179
+ * - linear: number
180
+ * - exponential: number
181
+ * - random: [min, max]
182
+ * - dynamic: (state) => number | [min, max]
183
+ * @default 1000
184
+ * @note Required if `strategy` is provided, otherwise uses default
185
+ */
186
+ time:
187
+ | number
188
+ | [min: number, max: number]
189
+ | (state: PollState) => number | [min: number, max: number];
190
+
191
+ /**
192
+ * Maximum number of retry attempts before throwing an error.
193
+ * Use `Infinity` to keep retrying indefinitely.
194
+ * @default 3
195
+ */
196
+ limit?: number;
197
+
198
+ /**
199
+ * Controls how retries are counted:
200
+ * - true: Only consecutive errors count toward retry limit
201
+ * (resets counter on success)
202
+ * - false: All errors count toward retry limit regardless of
203
+ * successful responses between them
204
+ * @default true
205
+ */
206
+ consecutiveOnly?: boolean;
207
+ };
208
+
209
+ /**
210
+ * [Browser only] Controls polling behavior when page isn't visible
211
+ * - true: Pause polling when tab isn't active, and resume on active
212
+ * - false: Poll even when tab isn't focused
213
+ * @default true
214
+ * @note Every started cycle (poll or retry) finishes before pausing
215
+ */
216
+ pauseWhenHidden?: boolean;
217
+ }
218
+ ```
219
+
220
+ ### PollState
221
+
222
+ State object passed to delay/retry time producer functions:
223
+
224
+ ```typescript
225
+ interface PollState<T> {
226
+ /** Latest value from the source. For `interval` polling type,
227
+ * first emission is undefined. */
228
+ value: T | undefined;
229
+
230
+ /** Latest error when retrying */
231
+ error: any | undefined;
232
+
233
+ /** Total number of successful poll operations */
234
+ pollCount: number;
235
+
236
+ /** Total number of retry attempts */
237
+ retryCount: number;
238
+
239
+ /** Current number of consecutive retry attempts */
240
+ consecutiveRetryCount: number;
241
+ }
242
+
243
+ /** Note: pollCount + retryCount = total attempts */
244
+ ```
245
+
246
+ ## 📚 Additional Resources
247
+
248
+ - **[Troubleshooting Guide](docs/TROUBLESHOOTING.md)** - Common issues and solutions
249
+ - **[V2 Changes](docs/V2_CHANGES.md)** - Overview of the changes and migration steps
250
+
251
+ ## 🤝 Contributing
252
+
253
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
254
+
255
+ Have a question? Check out [GitHub Discussions](https://github.com/mmustra/rxjs-poll/discussions) to ask questions, share ideas, or get help from the community.
256
+
257
+ ## 🙌 Credits
258
+
259
+ This library is inspired by [rx-polling](https://github.com/jiayihu/rx-polling), which creates an Observable for polling.
260
+
261
+ ## 📄 License
262
+
263
+ [MIT](LICENSE)