Skip to content
Browse files

Async timeout

  • Loading branch information...
1 parent 6474a3b commit 97aead481bcbfa7a9a335b85000023311110127e @VictorNicollet committed Feb 1, 2013
Showing with 8 additions and 6 deletions.
  1. +7 −5 src/async.ml
  2. +1 −1 src/async.mli
View
12 src/async.ml
@@ -143,12 +143,14 @@ module Make = functor(DB:CouchDB.CONFIG) -> struct
return None
- let run_task defined ctx =
+ let run_task ?timeout defined ctx =
let reschedule = ref (return ()) in
- try Run.eval ctx (run_next defined reschedule)
+ let timeout = BatOption.map Run.timeout timeout in
+ try Run.eval ?timeout ctx (run_next defined reschedule)
with
| Reschedule -> Run.eval ctx (!reschedule) ; None
- | exn -> log "Ohm.Async: task failed with %S" (Printexc.to_string exn) ; None
+ | Run.Timeout -> Util.log "Ohm.Async: task timed out" ; None
+ | exn -> Util.log "Ohm.Async: task failed with %S" (Printexc.to_string exn) ; None
(* This is the manager. It has no dependency on CouchDB. *)
@@ -194,7 +196,7 @@ module Make = functor(DB:CouchDB.CONFIG) -> struct
method stats : ('ctx,'stats) Run.t = stats ()
- method run new_ctx =
+ method run ?timeout new_ctx =
if not (BatPSet.is_empty undefined) then begin
BatPSet.iter (log "Ohm.Async: task %S not defined") undefined ;
failwith "Async tasks were not defined"
@@ -211,7 +213,7 @@ module Make = functor(DB:CouchDB.CONFIG) -> struct
process more next
in
- let list = (run_task defined,1,ref None) :: periodic in
+ let list = (run_task ?timeout defined,1,ref None) :: periodic in
process false list
View
2 src/async.mli
@@ -96,7 +96,7 @@ module Make : functor(DB:CouchDB.CONFIG) -> sig
[false] if there is nothing left to run (this information can be
used to sleep for a little while).
*)
- method run : (unit -> 'ctx) -> bool
+ method run : ?timeout:float -> (unit -> 'ctx) -> bool
end

0 comments on commit 97aead4

Please sign in to comment.
Something went wrong with that request. Please try again.