diff --git a/behavior.ml b/behavior.ml index 43c14cfb..32ae6f83 100644 --- a/behavior.ml +++ b/behavior.ml @@ -77,9 +77,9 @@ let test_signal s = TestFun (fun () -> React.S.value s) let wait e = Wait e -let timeout f = Sequence (false, [Timeout f; Fail]) +let timeout f = Sequence (false, [Timeout f; fail]) -let delay f = Sequence (false, [Timeout f; Succeed]) +let delay f = Sequence (false, [Timeout f; succeed]) let do_ act = Do act @@ -87,10 +87,16 @@ let do_succeed act = Do (fun () -> act (); true) let if_ s then_ else_ = If (s, then_, else_) +let when_ s t = if_ s t succeed + +let while_ s l = Sequence (true, (test_signal s) :: l) + let sequence ?(loop=false) l = assert (l <> []); Sequence (loop, l) +let repeat t = sequence ~loop:true [t] + let select ?(strat=strategy_inorder) l = assert (l <> []); Select (strat, l) diff --git a/behavior.mli b/behavior.mli index 428d7746..6a06238d 100644 --- a/behavior.mli +++ b/behavior.mli @@ -109,9 +109,18 @@ val do_succeed : (unit -> unit) -> tree val if_ : bool React.signal -> tree -> tree -> tree (** Conditional choice, based on the current value of the signal *) +val when_ : bool React.signal -> tree -> tree + (** Run the given tree if the signal is true, else succeed *) + +val while_ : bool React.signal -> tree list -> tree + (** While the signal is true, run the subtrees *) + val sequence : ?loop:bool -> tree list -> tree (** Sequence of sub-trees to run *) +val repeat : tree -> tree + (** Repeat the same tree indefinitely *) + val select : ?strat:select_strategy -> tree list -> tree (** Choice among the subtrees. The strategy defines in which order subtrees are tried. *)