<commit_before># soabase-stages

[![Build Status](https://travis-ci.org/soabase/soabase-stages.svg?branch=master)](https://travis-ci.org/soabase/soabase-stages)

A facade that makes staged/pipelined CompletableFutures much easier to create and manage

## Use Cases

- You have a sequence of tasks that pipeline or chain
- These tasks can be executed synchronously or asynchronously
- You might need to abort the chain in the middle
- You might need to provide a timeout for the tasks

Most of this can be done with Java 8's CompletableFuture/CompletionStage today. Timeouts
must be added manually (or wait for Java 9). Aborting tasks is not supported. Also, the
CompletableFuture/CompletionStage API is awkward and difficult to use.

## StagedFuture

`StagedFuture` simplifies CompletableFuture/CompletionStage so that you can write code like this:

```java
StagedFuture.async(executor)
    .then(() -> queryDatabaseFor("something")).withTimeout(Duration.ofSeconds(25))
    .then(record -> applyRecord(record))
    .whenComplete(result -> handleResult(result))
    .whenFailed(e -> handleFailure(e));
``` 
<commit_msg>more doc<commit_after># soabase-stages

[![Build Status](https://travis-ci.org/soabase/soabase-stages.svg?branch=master)](https://travis-ci.org/soabase/soabase-stages)

A facade that makes staged/pipelined CompletableFutures much easier to create and manage

## Use Cases

- You have a sequence of tasks that pipeline or chain
- These tasks can be executed synchronously or asynchronously
- You might need to abort the chain in the middle
- You might need to provide a timeout for the tasks

Most of this can be done with Java 8's CompletableFuture/CompletionStage today. Timeouts
must be added manually (or wait for Java 9). Aborting tasks is not supported. Also, the
CompletableFuture/CompletionStage API is awkward and difficult to use.

## StagedFuture

`StagedFuture` simplifies CompletableFuture/CompletionStage so that you can write code like this:

```java
StagedFuture.async(executor)
    .then(() -> queryDatabaseFor("something")).withTimeout(Duration.ofSeconds(25))
    .thenIf(record -> applyRecord(record)) // chain aborts if no record found
    .whenComplete(result -> handleResult(result))
    .whenFailed(e -> handleFailure(e));
``` 

{'fraction_non_alphanumeric': 0.09259259259259259, 'fraction_numerical': 0.003527336860670194, 'mean_word_length': 4.832904884318766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7330779', 'n_tokens_mistral': 659, 'n_tokens_neox': 637, 'n_words': 235}