Skip to content

Commit a69cdb0

Browse files
committed
fix(nodejs:website): Fix timer of vultr latency.
1 parent cc0c0e9 commit a69cdb0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

nodejs/packages/website/pages/tools/vultr-latency.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ function VultrNetworks(props: Props) {
2828
const [networks, setNetworks] = useState(hosts);
2929

3030
useEffect(() => {
31-
let reject;
32-
let timer;
31+
let isStopped: boolean = false;
3332
const run = async () => {
33+
out:
3434
while (true) {
3535
for (let h of hosts) {
36+
if (isStopped) break out;
3637
const {host, id} = h;
3738
let newNetworks;
3839
try {
@@ -83,21 +84,15 @@ function VultrNetworks(props: Props) {
8384
return m > n ? 1 : -1;
8485
});
8586
setNetworks(computed);
86-
try {
87-
await new Promise((resolve, r) => {
88-
reject = r;
89-
timer = setTimeout(resolve, 1000);
90-
});
91-
} catch(e) {
92-
return;
93-
}
87+
await new Promise((resolve, r) => {
88+
setTimeout(resolve, 1000);
89+
});
9490
}
9591
}
9692
};
9793
run();
9894
return () => {
99-
reject?.();
100-
clearTimeout(timer);
95+
isStopped = true;
10196
};
10297
}, []);
10398

0 commit comments

Comments
 (0)