1- class virtual ['a ] clock_base : object
2- method virtual now : 'a
3- method virtual sleep_until : 'a -> unit
4- end
1+ open Std
52
6- class virtual clock : object
7- inherit [float ] clock_base
8- end
3+ type 'a clock_ty = [`Clock of 'a ]
4+ type 'a clock_base = 'a r constraint 'a = [> _ clock_ty ]
5+
6+ type 'a clock = ([> float clock_ty ] as 'a ) r
97
10- val now : # clock -> float
8+ val now : _ clock -> float
119(* * [now t] is the current time since 00:00:00 GMT, Jan. 1, 1970 - in seconds - according to [t]. *)
1210
13- val sleep_until : # clock -> float -> unit
11+ val sleep_until : _ clock -> float -> unit
1412(* * [sleep_until t time] waits until the given time is reached. *)
1513
16- val sleep : # clock -> float -> unit
14+ val sleep : _ clock -> float -> unit
1715(* * [sleep t d] waits for [d] seconds. *)
1816
1917(* * Monotonic clocks. *)
@@ -24,43 +22,42 @@ module Mono : sig
2422
2523 A monotonic clock may or may not include time while the computer is suspended. *)
2624
27- class virtual t : object
28- inherit [Mtime. t ] clock_base
29- end
25+ type ty = Mtime .t clock_ty
26+ type 'a t = ([> ty ] as 'a ) r
3027
31- val now : # t -> Mtime. t
28+ val now : _ t -> Mtime .t
3229 (* * [now t] is the current time according to [t]. *)
3330
34- val sleep_until : # t -> Mtime. t -> unit
31+ val sleep_until : _ t -> Mtime .t -> unit
3532 (* * [sleep_until t time] waits until [time] before returning. *)
3633
37- val sleep : # t -> float -> unit
34+ val sleep : _ t -> float -> unit
3835 (* * [sleep t d] waits for [d] seconds. *)
3936
40- val sleep_span : # t -> Mtime. span -> unit
37+ val sleep_span : _ t -> Mtime .span -> unit
4138 (* * [sleep_span t d] waits for duration [d]. *)
4239end
4340
4441(* * {2 Timeouts} *)
4542
4643exception Timeout
4744
48- val with_timeout : # clock -> float -> (unit -> ('a , 'e ) result ) -> ('a , [> `Timeout] as 'e ) result
45+ val with_timeout : _ clock -> float -> (unit -> ('a , 'e ) result ) -> ('a , [> `Timeout ] as 'e ) result
4946(* * [with_timeout clock d fn] runs [fn ()] but cancels it after [d] seconds. *)
5047
51- val with_timeout_exn : # clock -> float -> (unit -> 'a ) -> 'a
48+ val with_timeout_exn : _ clock -> float -> (unit -> 'a ) -> 'a
5249(* * [with_timeout_exn clock d fn] runs [fn ()] but cancels it after [d] seconds,
5350 raising exception {!exception-Timeout}. *)
5451
5552(* * Timeout values. *)
5653module Timeout : sig
5754 type t
5855
59- val v : # Mono. t -> Mtime.Span. t -> t
56+ val v : _ Mono .t -> Mtime.Span .t -> t
6057 (* * [v clock duration] is a timeout of [duration], as measured by [clock].
6158 Internally, this is just the tuple [(clock, duration)]. *)
6259
63- val seconds : # Mono. t -> float -> t
60+ val seconds : _ Mono .t -> float -> t
6461 (* * [seconds clock duration] is a timeout of [duration] seconds, as measured by [clock]. *)
6562
6663 val none : t
@@ -77,3 +74,21 @@ module Timeout : sig
7774 (* * [pp] formats a timeout as a duration (e.g. "5s").
7875 This is intended for use in error messages and logging and is rounded. *)
7976end
77+
78+ module Pi : sig
79+ module type CLOCK = sig
80+ type t
81+ type time
82+
83+ val now : t -> time
84+ val sleep_until : t -> time -> unit
85+ end
86+
87+ type (_, _, _) Resource.pi + =
88+ Clock : ('t , (module CLOCK with type t = 't and type time = 'time ),
89+ [> 'time clock_ty ]) Resource .pi
90+
91+ val clock :
92+ (module CLOCK with type t = 't and type time = 'time ) ->
93+ ('t , [> 'time clock_ty ]) Resource .handler
94+ end
0 commit comments