diff --git a/behavior.ml b/behavior.ml index 32ae6f83..a2c5d69e 100644 --- a/behavior.ml +++ b/behavior.ml @@ -168,6 +168,7 @@ module Fut = struct let map f fut = let res, send = create () in subscribe fut (fun x -> send (f x)); + subscribe res (fun _ -> ignore fut); (* keep ref *) res let first l = diff --git a/behavior.mli b/behavior.mli index 6a06238d..34c98af3 100644 --- a/behavior.mli +++ b/behavior.mli @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (** {2 Behavior tree} *) +(** A behavior tree *) type tree = private | Test of bool React.event (* test the next occurrence *) | TestFun of (unit -> bool) (* call and test value *) @@ -59,12 +60,13 @@ type tree = private | Select of select_strategy * tree list (* select one subtree *) | Parallel of parallel_strategy * tree list (* run all subtrees in parallel *) | Closure of (unit -> tree) (* build a tree dynamically *) - | Succeed - | Fail - (** A behavior tree *) + | Succeed (* always succeed *) + | Fail (* always fail *) + and select_strategy = tree list -> (unit -> tree option) (** How to select a subtree to run. It may yield a different result each time it is called. *) + and parallel_strategy = | PSForall (** succeeds when all subtrees succeed *) | PSExists (** succeeds when some subtree succeeds (kill the others) *)