Callbacks are not being executed for already completed completion stages.
warownia1 opened this issue · comments
Callbacks attached to already completed CompletionStage
s returned by CompletableFuture#completedStage()
static factory method should be called just after being attached, but they are not. The issue doesn't occur when #completedFuture
is being used instead.
Example:
public class CompletionStageTest
{
public static void main(String[] args) {
CompletableFuture<String> future1 = new CompletableFuture<>();
future1.thenAccept(System.out::println);
future1.complete("Future 1");
CompletionStage<String> future2 = CompletableFuture.completedFuture("Future 2");
future2.thenAccept(System.out::println);
CompletionStage<String> future3 = CompletableFuture.completedStage("Future 3");
future3.thenAccept(System.out::println);
}
}
The last callback printing "Future 3" is not executed but it should be.
fix is pushed. Several Java 9 methods added to CompletableFuture
…On Thu, Feb 4, 2021 at 8:06 AM Mateusz Warowny ***@***.***> wrote:
Callbacks attached to already completed CompletionStages returned by
CompletableFuture#completedStage() static factory method should be called
just after being attached, but they are not. The issue doesn't occur when
#completedFuture is being used instead.
Example:
public class CompletionStageTest
{
public static void main(String[] args) {
CompletableFuture<String> future1 = new CompletableFuture<>();
future1.thenAccept(System.out::println);
future1.complete("Future 1");
CompletionStage<String> future2 = CompletableFuture.completedFuture("Future 2");
future2.thenAccept(System.out::println);
CompletionStage<String> future3 = CompletableFuture.completedStage("Future 3");
future3.thenAccept(System.out::println);
}
}
The last callback printing "Future 3" is not executed but it should be.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#208>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEHNCW7NKKHVHHWD6TE7HE3S5KSVFANCNFSM4XC4LZ7A>
.
--
Robert M. Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
If nature does not answer first what we want,
it is better to take what answer we get.
-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
*We stand on the homelands of the Wahpekute Band of the Dakota Nation. We
honor with gratitude the people who have stewarded the land throughout the
generations and their ongoing contributions to this region. We acknowledge
the ongoing injustices that we have committed against the Dakota Nation,
and we wish to interrupt this legacy, beginning with acts of healing and
honest storytelling about this place.*