@statewalker/webrun-http-browser 0.4.2 → 0.6.0

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.
@@ -1,31 +0,0 @@
1
- import * as workerTimer from "https://unpkg.com/worker-timers@7.0.74/build/es2019/module.js?module";
2
-
3
- export function startHeartbit({
4
- timeout = 10 * 1000,
5
- url = "./ping", // 10 seconds
6
- }) {
7
- return callPeriodically(async () => {
8
- const _res = await fetch(url);
9
- }, timeout);
10
- }
11
-
12
- export async function callPeriodically(action, timeout) {
13
- let timerId,
14
- stopped = false;
15
- async function run() {
16
- try {
17
- await action();
18
- } catch (err) {
19
- console.error(err);
20
- }
21
- timerId = !stopped ? workerTimer.setTimeout(run, timeout) : 0;
22
- }
23
- run();
24
- return () => {
25
- stopped = true;
26
- if (timerId) {
27
- workerTimer.clearTimeout(timerId);
28
- timerId = 0;
29
- }
30
- };
31
- }