Novah Documentation

novah.async

Functions for working with asynchronous computations using java.util.concurrent.CompletableFuture.

Types

Declarations


get

visibility: public
type: CompletableFuture a -> a

Blocks the future until it returns a result.


getOr

visibility: public
type: CompletableFuture a -> a -> a

Returns the value inside the future if it's completed, or return the default value.


wait

visibility: public
type: CompletableFuture a -> Int64 -> TimeUnit -> Option a

Blocks the future until it returns a result. If no result is returned until the timeout is reached, returns None.


complete

visibility: public
type: CompletableFuture a -> a -> Boolean

If this future is not yet completed, complete it with value. Returns true if the future transitioned to a completed state.


isDone

visibility: public
type: CompletableFuture a -> Boolean

Returns true if this future is completed in any form.


isCancelled

visibility: public
type: CompletableFuture a -> Boolean

Returns true if this future is cancelled.


new

visibility: public
type: (Unit -> a) -> CompletableFuture a

Creates a future that will run this function asynchronously.


newWith

visibility: public
type: Executor -> (Unit -> a) -> CompletableFuture a

Creates a future that will run this function asynchronously. The function will run in the given executor.


sleep

visibility: public
type: Int64 -> TimeUnit -> CompletableFuture Unit

Creates a future that will do nothing for the given time.


map

visibility: public
type: (a -> b) -> CompletableFuture a -> CompletableFuture b

Maps the given function asynchronously taking the result of this future as argument.


flatMap

visibility: public
type: (a -> CompletableFuture b) -> CompletableFuture a -> CompletableFuture b

Maps the given function asynchronously taking the result of this future as argument. Flattens the result to a single future.


combine

visibility: public
type: (a -> b -> c) -> CompletableFuture a -> CompletableFuture b -> CompletableFuture c

Runs the given function asynchronously with the result of both futures, returning a new future. The two futures will run independently.


all

visibility: public
type: List (CompletableFuture a) -> CompletableFuture Unit

Creates a single future that will be completed when all the given futures are completed.


any

visibility: public
type: List (CompletableFuture a) -> CompletableFuture a

Creates a single future that will be completed when any the given futures are completed.


exceptionally

visibility: public
type: (Throwable -> a) -> CompletableFuture a -> CompletableFuture a

Handles the exception in this future so it doesn't propagate down the chain. The function will only be called in case of an exception.


handle

visibility: public
type: (Result a Throwable -> b) -> CompletableFuture a -> CompletableFuture b

Adds a handler to this future. This function is similar to map but it handles exceptions as well.