aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/future.ml4
-rw-r--r--lib/future.mli5
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/future.ml b/lib/future.ml
index 8f2ae1df5..564535268 100644
--- a/lib/future.ml
+++ b/lib/future.ml
@@ -170,7 +170,7 @@ let transactify f x =
let purify_future f x = if is_over x then f x else purify f x
let compute x = purify_future (compute ~pure:false) x
let force x = purify_future (force ~pure:false) x
-let chain ?(greedy=false) ~pure x f =
+let chain ?(greedy=true) ~pure x f =
let y = chain ~pure x f in
if is_over x && greedy then ignore(force y);
y
@@ -180,6 +180,8 @@ let join kx =
kx := Finished v;
v
+let sink kx = if is_val kx then ignore(join kx)
+
let split2 ?greedy x =
chain ?greedy ~pure:true x (fun x -> fst x),
chain ?greedy ~pure:true x (fun x -> snd x)
diff --git a/lib/future.mli b/lib/future.mli
index 13f8ee961..785b2df53 100644
--- a/lib/future.mli
+++ b/lib/future.mli
@@ -115,7 +115,7 @@ val uuid : 'a computation -> UUID.t
* [force c; chain ~pure:false c g] is correct.
* [greedy]:
* The [greedy] parameter forces immediately the new computation if
- * the old one is_over (Exn or Val). Defaults to false. *)
+ * the old one is_over (Exn or Val). Defaults to true. *)
val chain : ?greedy:bool -> pure:bool ->
'a computation -> ('a -> 'b) -> 'b computation
@@ -128,6 +128,9 @@ val compute : 'a computation -> 'a value
* in a computation obtained by chaining on a joined future. *)
val join : 'a computation -> 'a
+(* Call this before stocking the future. If it is_val then it is joined *)
+val sink : 'a computation -> unit
+
(*** Utility functions ************************************************* ***)
val split2 : ?greedy:bool ->
('a * 'b) computation -> 'a computation * 'b computation