Hello,
I am trying to create a loop which do some stuff and when finished sleeps until
the next iteration at the top of the next minute.
I have the below code but I get a type error when trying to sleep.
import times, os
let minute = initDuration(seconds = 60)
let dt = getTime().utc
var dt2 = dt + minute
dt2 = initDateTime(dt2.monthday, dt2.month, dt2.year, dt2.hour, dt2.minute,
0, utc())
let dur = dt2-dt
let dt4 = getTime().utc
let sleeptime = dur.seconds*1000 + dur.milliseconds
echo("sleeptime: ", sleeptime)
sleep(sleeptime)
let dt5 = getTime().utc
echo("dt4: ",dt4)
echo("dt5: ", dt5)
Produces:
playground3.nim(17, 6) Error: type mismatch: got <int64>
but expected one of:
proc sleep(milsecs: int)
expression: sleep(sleeptime)
> exit status: 256
Run
If I comment out the call to sleep(), and run. I can take the resulting
sleeptime and manually place it in the code such as
sleep(16321)
Run
And it works just fine.
I do not understand why it doesn't work.
Any help and wisdom greatly appreciated.
Thanks.