com.yelstream.topp.furnace.reactive.integration.SubscriberToStream0 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.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();
}
}