Simplify get_time_delta()

This commit is contained in:
bobwen-dev 2021-01-25 16:01:54 +08:00
parent b384e4879d
commit b0772b8b7e
1 changed files with 5 additions and 8 deletions

View File

@ -94,22 +94,19 @@ get_time_delta = (url) ->
catch e
if not e.response?
console.log "#{step}#{e}"
wait_ms = argv.interval + start_at - Date.now()
if wait_ms > 0
await delay wait_ms
await delay argv.interval + start_at - Date.now()
continue
r = e.response
wait_ms = argv.interval + start_at - Date.now()
if wait_ms > 0
await delay wait_ms
r = e.response
duration = r.timings.end - r.timings.upload
server_moment = dayjs r.headers.date
delta = Math.round(server_moment - r.timings.end - duration / 2 + 500)
console.log "#{step}" + "#{delta} ms".padStart 10
await delay argv.interval + start_at - Date.now()
delta
delay = util.promisify (ms, cb) ->
return cb() if ms <= 0
setTimeout cb, ms
@ -127,4 +124,4 @@ do ->
if Math.abs(delta) < argv.threshold
console.log "There is no need to adjust the time"
return
await adjust_time delta
await adjust_time delta