com.yelstream.topp.furnace.reactive.integration.SubscriberToIterable0 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.Iterator;
import java.util.List;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.Flow.Subscription;
public class SubscriberToIterable0 implements Iterable, 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;
}
@Override
public Iterator iterator() {
while (!completed) {
// Busy-wait until onComplete is called
Thread.onSpinWait();
}
return items.iterator();
}
}