Skip to content

Latest commit

 

History

History
73 lines (49 loc) · 2.33 KB

CompletionStage.adoc

File metadata and controls

73 lines (49 loc) · 2.33 KB

CompletionStage

What is CompletionStage

Introduced in Java 8 (2014).

A java.util.concurrent.CompletionState interface represents an asynchronous or synchronous computation task.

This task performs an action or computes a value when another CompletionStage completes.

There are a few classifications that are identifiable via patterns in the method’s name.

Classifications

Core methods

Types of computation determined by method name pattern

Table 1. Core Methods
Pattern in method name Description

apply/Apply

Function computation on result or value of the CompletionStage

accept/Accept

Consumer computation on result or value of the CompletionStage

run/Run

Runnable computation

Action methods

Actions performed determined by method name pattern

Table 2. Action methods
Pattern in method name Description

Compose

Similar to apply, returns a new CompletionStage after the completion of the current one, thus allowing pipelines

Combine

Combine results of two completion stages into a BiFunction and returns a new CompletionStage

exceptionally

handle any exception via a Function that returns a CompletedStage, successful completion is returned as the value of CompletionStage

whenComplete

handle either successful result or exception passed as a BiConsumer and returns a new CompletionStage

handle

handle either successful result or exception passed as a BiFunction and returns a new CompletionStage

Synchronicity

Synchronicity of the stage is either Sync or Async

Table 3. Synchronicity
Pattern in method name Description

<nothing>

synchronous

Async

asynchronous

Post Execution

Actions to perform post-execution

Table 4. Post Execution
Pattern in method name Description

then

a single stage

Both

both of two stages

Either

either of two stages