diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/future.ml | 5 | ||||
| -rw-r--r-- | lib/future.mli | 2 |
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/future.ml b/lib/future.ml index 1e9cada513..d8f7b3a947 100644 --- a/lib/future.ml +++ b/lib/future.ml @@ -111,6 +111,11 @@ let purify f x = v with e -> let e = Errors.push e in !unfreeze state; raise e +let transactify f x = + let state = !freeze () in + try f x + with e -> let e = Errors.push e in !unfreeze state; raise e + let purify_future f x = match !x with | Val _ | Exn _ | Delegated | Dropped -> f x diff --git a/lib/future.mli b/lib/future.mli index 39be0c1806..f07d325e03 100644 --- a/lib/future.mli +++ b/lib/future.mli @@ -59,4 +59,6 @@ val set_freeze : (unit -> Dyn.t) -> (Dyn.t -> unit) -> unit (* Once set_freeze is called we can purify a computation *) val purify : ('a -> 'b) -> 'a -> 'b +(* And also let a function alter the state but backtrack if it raises exn *) +val transactify : ('a -> 'b) -> 'a -> 'b |
