com.yelstream.topp.furnace.reactive.integration.SubscriberExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of topp-furnace-reactive-integration Show documentation
Show all versions of topp-furnace-reactive-integration Show documentation
Topp Furnace Reactive Integration provides interactions between selected reactive frameworks.
The newest version!
package com.yelstream.topp.furnace.reactive.integration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow.*;
public class SubscriberExample {
public static void main(String[] args) {
// Example converting CompletionStage to Flow.Subscriber
CompletionStage completionStage = CompletableFuture.completedFuture("Hello, World!");
CompletionStageToSubscriber subscriber = new CompletionStageToSubscriber<>();
completionStage.whenComplete((result, error) -> {
if (error != null) {
subscriber.onError(error);
} else {
subscriber.onNext(result);
subscriber.onComplete();
}
});
// Example converting Flow.Subscriber to CompletionStage
SubscriberToCompletionStage converter = new SubscriberToCompletionStage<>();
completionStage = converter.getCompletionStage();
completionStage.thenAccept(result -> {
System.out.println("Received result: " + result);
}).exceptionally(ex -> {
System.err.println("Error: " + ex.getMessage());
return null;
});
}
}