定时器修正

This commit is contained in:
Shikong 2023-07-23 17:27:36 +08:00
parent a967f2dff2
commit 7983aa26f9

View File

@ -1,4 +1,4 @@
import {computed, reactive, ref, toRefs, toValue} from "vue";
import {reactive} from "vue";
import {net} from "frontend/wailsjs/go/models";
import IOCountersStat = net.IOCountersStat;
import {GetNetworkCounter} from "frontend/wailsjs/go/system/InfoUtils";
@ -30,6 +30,7 @@ const network = reactive({
function loopNetworkSumCounter(){
clearInterval(network.sumCounter.interval)
let delay = 1000
function loop(){
let fixed = 0
GetNetworkCounter(true).then(result=> {
@ -52,15 +53,15 @@ function loopNetworkSumCounter(){
network.sumCounter.data = result[0]
fixed = Math.max(1000 - now.diff(network.sumCounter.lastTime,'ms'), 0)
// 修正计时器延迟
fixed = Math.max(delay - now.diff(network.sumCounter.lastTime,'ms'), 0)
network.sumCounter.lastTime = now
})
// 每秒调用一次
network.sumCounter.interval = setTimeout(()=>{
loop()
},1000 - fixed)
},delay - fixed)
}
loop()
}