Continue app after restore from hibernate state

I run my app as a windows service. The app has several fibers which run statements perodically, like

spawn do 
  loop do 
    statements
    sleep 1.day
  end
end

My current understanding of the above code is, the sleep command yields the control back to the scheduler then the fiber is waked up by the scheduler in 86400 seconds.

What happens with the fiber reschedule time when I put my pc into hibernate state (e.g. in the evening) and restore from hibernate state (e.g. in the morning) ?

How does the scheduler handle leaps in time ?

1 Like

On Windows sleep schedules the fiber to be awakeable at Time.monotonic + 1.day at the moment it is called. The event loop then regularly checks whether the new, current Time.monotonic exceeds that stored value. This is in turn backed by QueryPerformanceCounter, which does include time spent during sleep states.

This Rust issue suggests the underlying implementations for Time.monotonic might not respect sleep times on other systems, but Iā€™m not sure whether that affects libevent.

3 Likes