You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function to be called every `delay` milliseconds. No parameters are passed to `fn` upon calling it.
76
96
77
-
##Documentation
97
+
#### `delayOrDelayCallback`
78
98
79
-
### Syntax
99
+
**Type**: `number | (() => number)`
80
100
81
-
```
82
-
poll(function, delay[, shouldStopPolling])
83
-
```
101
+
The delay (in milliseconds) to wait before calling the function `fn` again. If a function is provided instead of a number, it is evaluated during every polling cycle right before the wait period. If the delay is a negative number, zero will be used instead.
84
102
85
-
**Parameters**:
103
+
#### `shouldStopPolling` (optional)
86
104
87
-
-**Name**: `fn`<br>
88
-
**Type**: `() => any`<br>
89
-
**Required**: Yes<br>
90
-
**Description**: A function to be called every `delay` milliseconds. No parameters are passed to `fn` upon calling it.
91
-
-**Name**: `delayOrDelayCallback`<br>
92
-
**Type**: `number | (() => number)`<br>
93
-
**Required**: Yes<br>
94
-
**Description**: The delay (in milliseconds) to wait before calling the function `fn` again. If a function is provided instead of a number, it is evaluated during every polling cycle right before the wait period. If the delay is a negative number, zero will be used instead.
95
-
-**Name**: `shouldStopPolling`<br>
96
-
**Type**: `() => boolean | Promise<boolean>`<br>
97
-
**Required**: No<br>
98
-
**Default**: `() => false`<br>
99
-
**Description**: A function (or a promise resolving to a function) indicating whether to stop the polling process by returning a truthy value (e.g. `true`). The `shouldStopPolling` callback function is called twice during one polling cycle:
105
+
**Type**: `() => boolean | Promise<boolean>`<br>
106
+
**Default**: `() => false`
100
107
101
-
- After the result of the call to `fn` was successfully awaited (right before triggering a new delay period).
102
-
- After the `delay` has passed (right before calling `fn` again).
108
+
A function returning a boolean (or a function returning a promise resolving to a boolean) indicating whether to stop the polling process. The `shouldStopPolling` callback function is called twice during one polling cycle:
103
109
104
-
This guarantees two things:
110
+
- After the result of the call to `fn` was successfully awaited (right before triggering a new delay period).
111
+
- After the `delay` has passed (right before calling `fn` again).
105
112
106
-
- A currently active execution of `fn` will be completed.
107
-
- No new calls to `fn` will be triggered.
113
+
This guarantees two things:
108
114
109
-
**Return value**:
115
+
- A currently active execution of `fn` will be completed.
116
+
- No new calls to `fn` will be triggered.
117
+
118
+
### Return value
110
119
111
120
None.
112
121
@@ -137,7 +146,6 @@ You can pass a callback function to `poll` for its third parameter. It’s evalu
137
146
138
147
```js
139
148
let stopPolling =false
140
-
constshouldStopPolling= () => stopPolling
141
149
142
150
functionfn() {
143
151
console.log('Hello, beautiful!')
@@ -147,7 +155,7 @@ setTimeout(() => {
147
155
stopPolling =true
148
156
}, 1000)
149
157
150
-
poll(fn, 50, shouldStopPolling)
158
+
poll(fn, 50, () => stopPolling)
151
159
```
152
160
153
161
In this example, the `shouldStopPolling` callback function evaluates to `true` after the `setTimeout` function causes `stopPolling` to be set to `true` after 1000 milliseconds. The next time `shouldStopPolling` is evaluated, it will cause `poll` to exit normally.
0 commit comments