117 |
|
* public void onComplete() {} |
118 |
|
* }}</pre> |
119 |
|
* |
120 |
< |
* <p>When flow control is inapplicable, a subscriber may initially |
121 |
< |
* request an effectively unbounded number of items, as in: |
120 |
> |
* <p>The default value of {@link #defaultBufferSize} may provide a |
121 |
> |
* useful starting point for choosing request sizes and capacities in |
122 |
> |
* Flow components based on expected rates, resources, and usages. |
123 |
> |
* Or, when flow control is known to be always inapplicable, a |
124 |
> |
* subscriber may initially request an effectively unbounded number of |
125 |
> |
* items, as in: |
126 |
|
* |
127 |
|
* <pre> {@code |
128 |
|
* class UnboundedSubscriber<T> implements Subscriber<T> { |
278 |
|
|
279 |
|
// Support for static methods |
280 |
|
|
281 |
< |
static final long DEFAULT_BUFFER_SIZE = 64L; |
281 |
> |
static final int DEFAULT_BUFFER_SIZE = 256; |
282 |
> |
|
283 |
> |
/** |
284 |
> |
* Returns a default value for Publisher or Subscriber buffering, |
285 |
> |
* that may be used in the absence of other constraints. |
286 |
> |
* |
287 |
> |
* @implNote |
288 |
> |
* The current value returned is 256. |
289 |
> |
* |
290 |
> |
* @return the buffer size value |
291 |
> |
*/ |
292 |
> |
public static int defaultBufferSize() { |
293 |
> |
return DEFAULT_BUFFER_SIZE; |
294 |
> |
} |
295 |
|
|
296 |
|
abstract static class CompletableSubscriber<T,U> implements Subscriber<T>, |
297 |
|
Consumer<T> { |
366 |
|
|
367 |
|
/** |
368 |
|
* Equivalent to {@link #consume(long, Publisher, Consumer)} |
369 |
< |
* with a buffer size of 64. |
369 |
> |
* with {@link #defaultBufferSize}. |
370 |
|
* |
371 |
|
* @param <T> the published item type |
372 |
|
* @param publisher the publisher |
378 |
|
*/ |
379 |
|
public static <T> CompletableFuture<Void> consume( |
380 |
|
Publisher<T> publisher, Consumer<? super T> consumer) { |
381 |
< |
return consume(DEFAULT_BUFFER_SIZE, publisher, consumer); |
381 |
> |
return consume(defaultBufferSize(), publisher, consumer); |
382 |
|
} |
383 |
|
|
384 |
|
/** |
437 |
|
|
438 |
|
/** |
439 |
|
* Equivalent to {@link #stream(long, Publisher, Function)} |
440 |
< |
* with a buffer size of 64. |
440 |
> |
* with {@link #defaultBufferSize}. |
441 |
|
* |
442 |
|
* @param <T> the published item type |
443 |
|
* @param <R> the result type of the stream function |
451 |
|
public static <T,R> CompletableFuture<R> stream( |
452 |
|
Publisher<T> publisher, |
453 |
|
Function<? super Stream<T>,? extends R> streamFunction) { |
454 |
< |
return stream(DEFAULT_BUFFER_SIZE, publisher, streamFunction); |
454 |
> |
return stream(defaultBufferSize(), publisher, streamFunction); |
455 |
|
} |
456 |
|
} |