Skip to content

Instantly share code, notes, and snippets.

View Roiocam's full-sized avatar
🎯
Focusing

Andy(Jingzhang)Chen Roiocam

🎯
Focusing
View GitHub Profile
@Roiocam
Roiocam / gist:fb4ae743ecaafb7385f75dbaac3030f8
Created September 25, 2024 07:00
Java Future.firstCompletedOf Impl
public static <T> CompletableFuture<T> firstSuccessful(
List<CompletableFuture<T>> futures, Predicate<T> predicate) {
if (futures == null || futures.isEmpty()) {
throw new AsynchronousHelperException("No successful result found");
}
CompletableFuture<T> success = new CompletableFuture<>();
AtomicInteger ref = new AtomicInteger(futures.size());
Consumer<T> consumer =
t -> {
try {
@Roiocam
Roiocam / MiniReproduce.java
Created February 27, 2024 07:02
Akka#32330
import akka.actor.ActorPath;
import akka.actor.typed.ActorRef;
import akka.actor.typed.ActorSystem;
import akka.actor.typed.Behavior;
import akka.actor.typed.Props;
import akka.actor.typed.SpawnProtocol;
import akka.actor.typed.javadsl.AskPattern;
import akka.actor.typed.javadsl.Behaviors;
import org.junit.Assert;
import org.openjdk.jmh.annotations._
import java.util.concurrent.TimeUnit
import scala.annotation.nowarn
object CollectFirstBenchmark {
final val OperationsPerInvocation = 1000
}
@Roiocam
Roiocam / DeadlockCase.java
Created December 28, 2023 06:43
Akka Unit Test deadlock case
import akka.actor.ActorSystem;
import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Adapter;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;
import akka.actor.typed.javadsl.TimerScheduler;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/
/*
@Roiocam
Roiocam / TinyReproduce.java
Last active March 6, 2023 10:01
akka mailbox issue #31862
import akka.actor.ActorSystem;
import akka.actor.InternalActorRef;
import akka.actor.LocalActorRef;
import akka.actor.testkit.typed.javadsl.ActorTestKit;
import akka.actor.typed.ActorRef;
import akka.actor.typed.Props;
import akka.actor.typed.internal.adapter.ActorRefAdapter;
import akka.actor.typed.internal.adapter.PropsAdapter;
import akka.actor.typed.javadsl.Behaviors;