Module Future

module Future: sig .. end
Computations run in background.

type 'a t = java'util'concurrent'Future java_instance
The type of futures, that are computations run in background.
 
val cancel : 'a t -> bool -> bool
cancel f i attemps to cancel future f, i indicating whether to interrupt the computation if already started. Returns whether the future was cancelled; see cancel(...).
 
val get : 'a t -> 'a
Waits for the computation to complete, and returns its result; see get(...).
Raises
  • Java_exception if the thread is interrupted
  • Java_exception is the computation raised an uncaught exception
  • Java_exception if the computation was cancelled
 
val get_time : 'a t -> java_long -> TimeUnit.t -> 'a
get_time f t u is similar to get f, except that the current thread will at most wait for t (time value whose unit is u); see get(...).
Raises
  • Java_exception if the thread is interrupted
  • Java_exception is the computation raised an uncaught exception
  • Java_exception if the computation was cancelled
  • Java_exception if time has elapsed without completion
 
val is_cancelled : 'a t -> bool
Tests whether the task was cancelled before completion; see isCancelled(...).
 
val is_done : 'a t -> bool
Tests whether the computation is completed; see isDone(...).
 

Null value

 
val null : 'a t
The null value.
 
val is_null : 'a t -> bool
is_null obj returns true iff obj is equal to null.
 
val is_not_null : 'a t -> bool
is_not_null obj returns false iff obj is equal to null.
 

Miscellaneous

 
val wrap : 'a t -> 'a t option
wrap obj wraps the reference obj into an option type:
  • Some x if obj is not null;
  • None if obj is null.

 
val unwrap : 'a t option -> 'a t
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.