This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(name test_scheduler)
|
||||
(libraries stdune fiber))
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
open Stdune
|
||||
|
||||
type job = Job : (unit -> 'a) * 'a Fiber.Ivar.t -> job
|
||||
type t = job Queue.t
|
||||
|
||||
let create () : t = Queue.create ()
|
||||
|
||||
let yield t =
|
||||
Fiber.of_thunk
|
||||
@@ fun () ->
|
||||
let ivar = Fiber.Ivar.create () in
|
||||
Queue.push t (Job ((fun () -> ()), ivar));
|
||||
Fiber.Ivar.read ivar
|
||||
;;
|
||||
|
||||
let yield_gen (t : t) ~do_in_scheduler =
|
||||
Fiber.of_thunk
|
||||
@@ fun () ->
|
||||
let ivar = Fiber.Ivar.create () in
|
||||
Queue.push t (Job (do_in_scheduler, ivar));
|
||||
Fiber.Ivar.read ivar
|
||||
;;
|
||||
|
||||
exception Never
|
||||
|
||||
let run (t : t) fiber =
|
||||
Queue.clear t;
|
||||
Fiber.run fiber ~iter:(fun () ->
|
||||
match Queue.pop t with
|
||||
| None -> raise Never
|
||||
| Some (Job (job, ivar)) ->
|
||||
let v = job () in
|
||||
[ Fiber.Fill (ivar, v) ])
|
||||
;;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
(** Dummy scheduler for tests using fibers *)
|
||||
|
||||
type t
|
||||
|
||||
exception Never
|
||||
|
||||
val create : unit -> t
|
||||
val yield : t -> unit Fiber.t
|
||||
val yield_gen : t -> do_in_scheduler:(unit -> 'a) -> 'a Fiber.t
|
||||
val run : t -> 'a Fiber.t -> 'a
|
||||
Loading…
Add table
Add a link
Reference in a new issue