Home

thenAcceptAsync

thenAcceptAsync is a method of Java's CompletableFuture used to perform a side-effect action after a stage completes, with the action executed asynchronously. The method consumes the result of the preceding stage but does not produce a new value, and it returns a new CompletableFuture<Void> that completes when the action itself finishes.

There are two overloads: thenAcceptAsync(Consumer<? super T> action) and thenAcceptAsync(Consumer<? super T> action, Executor executor). In

If an Executor is supplied, the action runs using that executor. If no executor is provided, the

thenAcceptAsync contrasts with thenAccept, which may execute the action in the completion thread (potentially synchronously with

Usage notes include that the action can perform side effects such as logging, I/O, or updating external

both
cases,
when
the
previous
stage
completes
normally,
the
provided
Consumer
is
invoked
with
the
stage’s
result.
If
the
preceding
stage
completes
exceptionally,
the
returned
CompletableFuture
completes
exceptionally
and
the
action
is
not
invoked.
action
is
scheduled
to
run
asynchronously,
typically
in
the
common
ForkJoinPool.
the
completing
stage)
rather
than
asynchronously.
The
Async
variant
ensures
that
the
consumer
runs
asynchronously,
enabling
safer
separation
of
concerns
and
avoiding
blocking
the
completion
thread.
state,
without
producing
a
value
for
downstream
stages.
Any
exception
thrown
by
the
consumer
causes
the
returned
CompletableFuture
to
complete
exceptionally,
which
can
be
handled
via
further
composition
methods
such
as
exceptionally
or
handle.