Closed Nymphium closed 1 year ago
Yes, Get_monotonic_clock works that way (used to implement Eio_unix.sleep
).
Additionally, we can express it more commonly, such as switch
passed to Fiber
functions.
You can do that, but it removes the benefit of using switches, which is to make the lifetimes clear. Creating a switch at the top-level and using it implicitly everywhere means functions can leak resources easily (e.g. forgetting to close a file).
Anyway, Eio doesn't prevent you from doing that, but it also doesn't want to encourage it.
The function interfaces of the current Time require a clock, so we need to propagate the clock object from the eio main handler to the deeper call sites.
One opinion is to fetch
clock
byperform
ing effect such as: