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

com.yelstream.topp.furnace.reactive.integration.SubscriberToStream0 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.ArrayList;
import java.util.List;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.Flow.Subscription;

public class SubscriberToStream0 implements Subscriber {

    private final List items = new ArrayList<>();
    private boolean completed = false;

    @Override
    public void onSubscribe(Subscription subscription) {
        subscription.request(Long.MAX_VALUE); // Request all items
    }

    @Override
    public void onNext(T item) {
        items.add(item);
    }

    @Override
    public void onError(Throwable throwable) {
        // Handle error
        throwable.printStackTrace();
    }

    @Override
    public void onComplete() {
        completed = true;
    }

    public java.util.stream.Stream stream() {
        while (!completed) {
            // Busy-wait until onComplete is called
            Thread.onSpinWait();
        }
        return items.stream();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy