* Wait a specified number of milliseconds. * @param {number} ms * @returns {Promise }
(ms)
| 381 | * @returns {Promise<void>} |
| 382 | */ |
| 383 | function sleep(ms) { |
| 384 | return new Promise((resolve, reject) => { |
| 385 | const start = Date.now(); |
| 386 | |
| 387 | function tick() { |
| 388 | if (flowStopped) { |
| 389 | reject(new Error(STOP_ERROR_MESSAGE)); |
| 390 | return; |
| 391 | } |
| 392 | if (Date.now() - start >= ms) { |
| 393 | resolve(); |
| 394 | return; |
| 395 | } |
| 396 | setTimeout(tick, Math.min(100, Math.max(25, ms - (Date.now() - start)))); |
| 397 | } |
| 398 | |
| 399 | tick(); |
| 400 | }); |
| 401 | } |
| 402 | |
| 403 | async function humanPause(min = 250, max = 850) { |
| 404 | const duration = Math.floor(Math.random() * (max - min + 1)) + min; |
no test coverage detected