net.pincette.rs.Buffer Maven / Gradle / Ivy
package net.pincette.rs;
import static net.pincette.util.Collections.list;
import java.time.Duration;
import java.util.concurrent.Flow.Processor;
/**
* Buffers a number of values. It always requests the number of values from the publisher that
* equals the buffer size. This processor uses a shared thread.
*
* @param the value type.
* @since 1.7
* @author Werner Donn\u00e8
*/
public class Buffer extends Buffered {
public Buffer(final int size) {
super(size);
}
public Buffer(final int size, final Duration timeout) {
super(size, timeout);
}
public static Processor buffer(final int size) {
return new Buffer<>(size);
}
public static Processor buffer(final int size, final Duration timeout) {
return new Buffer<>(size, timeout);
}
protected boolean onNextAction(final T value) {
addValues(list(value));
emit();
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy