All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yelstream.topp.furnace.reactive.integration.SubscriberExample Maven / Gradle / Ivy

Go to download

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;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy