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.
- package/LICENSE +21 -21
- package/README.md +263 -263
- package/dist/cjs/index.js +134 -78
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +135 -79
- package/dist/esm/index.js.map +1 -1
- package/dist/types/common/service.d.ts +9 -0
- package/dist/types/common/service.d.ts.map +1 -0
- package/dist/types/constants/config.const.d.ts +1 -1
- package/dist/types/constants/state.const.d.ts +8 -0
- package/dist/types/constants/state.const.d.ts.map +1 -0
- package/dist/types/constants/timing.const.d.ts +6 -0
- package/dist/types/constants/timing.const.d.ts.map +1 -0
- package/dist/types/observables/factory.d.ts +11 -0
- package/dist/types/observables/factory.d.ts.map +1 -0
- package/dist/types/observables/interval-poller.d.ts +3 -3
- package/dist/types/observables/interval-poller.d.ts.map +1 -1
- package/dist/types/observables/pause-delay.d.ts +7 -0
- package/dist/types/observables/pause-delay.d.ts.map +1 -0
- package/dist/types/observables/repeat-poller.d.ts +3 -3
- package/dist/types/observables/repeat-poller.d.ts.map +1 -1
- package/dist/types/operators/retry-pol.operator.d.ts +11 -0
- package/dist/types/operators/retry-pol.operator.d.ts.map +1 -0
- package/dist/types/poll.d.ts +1 -1
- package/dist/types/poll.d.ts.map +1 -1
- package/dist/types/types/config.type.d.ts +1 -1
- package/dist/types/types/observables.type.d.ts +9 -21
- package/dist/types/types/observables.type.d.ts.map +1 -1
- package/dist/types/types/poll.type.d.ts +1 -6
- package/dist/types/types/poll.type.d.ts.map +1 -1
- package/dist/types/types/retry.type.d.ts +7 -0
- package/dist/types/types/retry.type.d.ts.map +1 -0
- package/dist/types/types/service.type.d.ts +18 -0
- package/dist/types/types/service.type.d.ts.map +1 -0
- package/dist/umd/index.js +134 -78
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +5 -5
- package/dist/types/common/state.d.ts +0 -8
- package/dist/types/common/state.d.ts.map +0 -1
- package/dist/types/observables/poller-factory.d.ts +0 -11
- package/dist/types/observables/poller-factory.d.ts.map +0 -1
- package/dist/types/observables/retry-operator.d.ts +0 -11
- 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
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
import {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* - '
|
|
131
|
-
*
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
* -
|
|
150
|
-
* -
|
|
151
|
-
* -
|
|
152
|
-
* -
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* - consecutiveOnly:
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
* -
|
|
179
|
-
* -
|
|
180
|
-
* -
|
|
181
|
-
* -
|
|
182
|
-
*
|
|
183
|
-
* @
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
|
188
|
-
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*
|
|
211
|
-
* -
|
|
212
|
-
*
|
|
213
|
-
* @
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
error
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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)
|