Skip to content

Commit 792ab06

Browse files
Merge pull request #917 from madroach/master
Remove obsolete second wakeup_paused
2 parents 75e479e + 6419816 commit 792ab06

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
* Fix marshall header size in Lwt_io.read_value. (Simmo Saan, #995)
4141

42+
====== Misc ======
43+
44+
* Resolve paused promises only once in main loop. This lets Lwt.pause behave identical to Lwt_unix.yield. (#917, Christopher Zimmermann, Favonia)
45+
4246

4347
===== 5.6.1 =====
4448

src/unix/lwt_main.ml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ open Lwt.Infix
1616

1717
let enter_iter_hooks = Lwt_sequence.create ()
1818
let leave_iter_hooks = Lwt_sequence.create ()
19-
let yielded = Lwt_sequence.create ()
2019

21-
let yield () = (Lwt.add_task_r [@ocaml.warning "-3"]) yielded
20+
let yield = Lwt.pause
2221

2322
let abandon_yielded_and_paused () =
24-
Lwt_sequence.clear yielded;
2523
Lwt.abandon_paused ()
2624

2725
let run p =
2826
let rec run_loop () =
29-
(* Fulfill paused promises now. *)
30-
Lwt.wakeup_paused ();
3127
match Lwt.poll p with
3228
| Some x ->
3329
x
@@ -36,20 +32,12 @@ let run p =
3632
Lwt_sequence.iter_l (fun f -> f ()) enter_iter_hooks;
3733

3834
(* Do the main loop call. *)
39-
let should_block_waiting_for_io =
40-
Lwt.paused_count () = 0 && Lwt_sequence.is_empty yielded in
35+
let should_block_waiting_for_io = Lwt.paused_count () = 0 in
4136
Lwt_engine.iter should_block_waiting_for_io;
4237

43-
(* Fulfill paused promises again. *)
38+
(* Fulfill paused promises. *)
4439
Lwt.wakeup_paused ();
4540

46-
(* Fulfill yield promises. *)
47-
if not (Lwt_sequence.is_empty yielded) then begin
48-
let tmp = Lwt_sequence.create () in
49-
Lwt_sequence.transfer_r yielded tmp;
50-
Lwt_sequence.iter_l (fun resolver -> Lwt.wakeup resolver ()) tmp
51-
end;
52-
5341
(* Call leave hooks. *)
5442
Lwt_sequence.iter_l (fun f -> f ()) leave_iter_hooks;
5543

src/unix/lwt_main.mli

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,19 @@ val yield : unit -> unit Lwt.t [@@deprecated "Use Lwt.pause instead"]
4949
5050
@deprecated Since 5.5.0 [yield] is deprecated in favor of the more general
5151
{!Lwt.pause} in order to avoid discrepancies in resolution (see below) and
52-
stay compatible with other execution environments such as js_of_ocaml.
52+
stay compatible with other execution environments such as js_of_ocaml. *)
5353

54-
Currently, paused promises are resolved more frequently than yielded promises.
55-
The difference is unintended but existing applications could depend on it.
56-
Unifying the two pools of promises into one in the future would eliminate
57-
possible discrepancies and simplify the code. *)
58-
59-
val abandon_yielded_and_paused : unit -> unit
54+
val abandon_yielded_and_paused : unit -> unit [@@deprecated "Use Lwt.abandon_paused instead"]
6055
(** Causes promises created with {!Lwt.pause} and {!Lwt_main.yield} to remain
6156
forever pending.
6257
63-
[yield] is now deprecated in favor of the more general {!Lwt.pause}.
64-
Once [yield] is phased out, this function will be deprecated as well.
58+
(Note that [yield] is deprecated in favor of the more general {!Lwt.pause}.)
6559
6660
This is meant for use with {!Lwt_unix.fork}, as a way to “abandon” more
67-
promise chains that are pending in your process. *)
61+
promise chains that are pending in your process.
62+
63+
@deprecated Since 5.7 [abandon_yielded_and_paused] is deprecated in favour
64+
of [Lwt.abandon_paused]. *)
6865

6966

7067

src/unix/lwt_unix.cppo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let sleep delay =
123123
Lwt.on_cancel waiter (fun () -> Lwt_engine.stop_event ev);
124124
waiter
125125

126-
let yield = (Lwt_main.yield [@warning "-3"])
126+
let yield = Lwt.pause
127127

128128
let auto_yield timeout =
129129
let limit = ref (Unix.gettimeofday () +. timeout) in

0 commit comments

Comments
 (0)