Skip to content

Commit ce4b392

Browse files
committed
Deprecate Timeout.of_s
Timeouts should be using a monotonic clock.
1 parent 42f2a31 commit ce4b392

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib_eio/time.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module Timeout : sig
5757
type t
5858

5959
val of_s : #clock -> float -> t
60-
(** [of_s clock duration] is a timeout of [duration] seconds, as measured by [clock]. *)
60+
[@@deprecated "Use [seconds] instead, with a monotonic clock"]
6161

6262
val v : #Mono.t -> Mtime.Span.t -> t
6363
(** [v clock duration] is a timeout of [duration], as measured by [clock].

tests/network.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ First attempt times out:
685685

686686
```ocaml
687687
# Eio_mock.Backend.run @@ fun () ->
688-
let clock = Eio_mock.Clock.make () in
689-
let timeout = Eio.Time.Timeout.of_s clock 10. in
688+
let clock = Eio_mock.Clock.Mono.make () in
689+
let timeout = Eio.Time.Timeout.seconds clock 10. in
690690
Eio_mock.Net.on_getaddrinfo net [`Return [addr1; addr2]];
691691
let mock_flow = Eio_mock.Flow.make "flow" in
692692
Eio_mock.Net.on_connect net [`Run Fiber.await_cancel; `Return mock_flow];
@@ -698,7 +698,7 @@ First attempt times out:
698698
)
699699
)
700700
(fun () ->
701-
Eio_mock.Clock.advance clock
701+
Eio_mock.Clock.Mono.advance clock
702702
);;
703703
+mock-net: getaddrinfo ~service:http www.example.com
704704
+mock-net: connect to tcp:127.0.0.1:80
@@ -715,8 +715,8 @@ Both attempts time out:
715715

716716
```ocaml
717717
# Eio_mock.Backend.run @@ fun () ->
718-
let clock = Eio_mock.Clock.make () in
719-
let timeout = Eio.Time.Timeout.of_s clock 10. in
718+
let clock = Eio_mock.Clock.Mono.make () in
719+
let timeout = Eio.Time.Timeout.seconds clock 10. in
720720
Eio_mock.Net.on_getaddrinfo net [`Return [addr1; addr2]];
721721
Eio_mock.Net.on_connect net [`Run Fiber.await_cancel; `Run Fiber.await_cancel];
722722
Fiber.both
@@ -726,10 +726,10 @@ Both attempts time out:
726726
)
727727
)
728728
(fun () ->
729-
Eio_mock.Clock.advance clock;
729+
Eio_mock.Clock.Mono.advance clock;
730730
Fiber.yield ();
731731
Fiber.yield ();
732-
Eio_mock.Clock.advance clock
732+
Eio_mock.Clock.Mono.advance clock
733733
);;
734734
+mock-net: getaddrinfo ~service:http www.example.com
735735
+mock-net: connect to tcp:127.0.0.1:80

tests/time.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ let rec loop () =
113113
### Timeouts
114114

115115
```ocaml
116-
# run @@ fun ~clock ->
116+
# Eio_main.run @@ fun env ->
117+
let clock = Eio.Stdenv.mono_clock env in
117118
Eio.Time.Timeout.(run_exn none) (fun () -> ());
118-
let t = Eio.Time.Timeout.of_s clock 0.0001 in
119+
let t = Eio.Time.Timeout.seconds clock 0.0001 in
119120
Eio.Time.Timeout.run_exn t (fun () -> Fiber.await_cancel ());;
120121
Exception: Eio__Time.Timeout.
121122
```
122123

123124
```ocaml
124-
# run @@ fun ~clock ->
125+
# Eio_main.run @@ fun env ->
126+
let clock = Eio.Stdenv.mono_clock env in
125127
let show d =
126-
let t = Eio.Time.Timeout.of_s clock d in
128+
let t = Eio.Time.Timeout.seconds clock d in
127129
traceln "%g -> %a" d Eio.Time.Timeout.pp t
128130
in
129131
show 0.000000001;

0 commit comments

Comments
 (0)