mirror of
https://github.com/bobwen-dev/htpdate
synced 2025-04-11 23:00:44 +02:00
Simplify get_time_delta()
This commit is contained in:
parent
b384e4879d
commit
b0772b8b7e
13
index.coffee
13
index.coffee
@ -94,22 +94,19 @@ get_time_delta = (url) ->
|
|||||||
catch e
|
catch e
|
||||||
if not e.response?
|
if not e.response?
|
||||||
console.log "#{step}#{e}"
|
console.log "#{step}#{e}"
|
||||||
wait_ms = argv.interval + start_at - Date.now()
|
await delay argv.interval + start_at - Date.now()
|
||||||
if wait_ms > 0
|
|
||||||
await delay wait_ms
|
|
||||||
continue
|
continue
|
||||||
r = e.response
|
r = e.response
|
||||||
wait_ms = argv.interval + start_at - Date.now()
|
|
||||||
if wait_ms > 0
|
|
||||||
await delay wait_ms
|
|
||||||
duration = r.timings.end - r.timings.upload
|
duration = r.timings.end - r.timings.upload
|
||||||
server_moment = dayjs r.headers.date
|
server_moment = dayjs r.headers.date
|
||||||
delta = Math.round(server_moment - r.timings.end - duration / 2 + 500)
|
delta = Math.round(server_moment - r.timings.end - duration / 2 + 500)
|
||||||
console.log "#{step}" + "#{delta} ms".padStart 10
|
console.log "#{step}" + "#{delta} ms".padStart 10
|
||||||
|
await delay argv.interval + start_at - Date.now()
|
||||||
delta
|
delta
|
||||||
|
|
||||||
|
|
||||||
delay = util.promisify (ms, cb) ->
|
delay = util.promisify (ms, cb) ->
|
||||||
|
return cb() if ms <= 0
|
||||||
setTimeout cb, ms
|
setTimeout cb, ms
|
||||||
|
|
||||||
|
|
||||||
@ -127,4 +124,4 @@ do ->
|
|||||||
if Math.abs(delta) < argv.threshold
|
if Math.abs(delta) < argv.threshold
|
||||||
console.log "There is no need to adjust the time"
|
console.log "There is no need to adjust the time"
|
||||||
return
|
return
|
||||||
await adjust_time delta
|
await adjust_time delta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user