|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-present, RxJava Contributors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 | + * compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 | + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 | + * the License for the specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package io.reactivex.rxjava4.core; |
| 15 | + |
| 16 | +import java.util.NoSuchElementException; |
| 17 | +import java.util.concurrent.CompletionStage; |
| 18 | + |
| 19 | +import io.reactivex.rxjava4.annotations.NonNull; |
| 20 | + |
| 21 | +/** |
| 22 | + * A realized stream which can then be consumed asynchronously in steps. |
| 23 | + * Think of it as the {@IAsyncEnumerator} of the Java world. Runs best on Virtual Threads. |
| 24 | + * @param <T> the element type. |
| 25 | + * TODO proper docs |
| 26 | + * @since 4.0.0 |
| 27 | + */ |
| 28 | +public interface Streamer<@NonNull T> { |
| 29 | + |
| 30 | + /** |
| 31 | + * Determine if there are more elements available from the source. |
| 32 | + * @return eventually true or false, indicating availability or termination |
| 33 | + */ |
| 34 | + @NonNull |
| 35 | + CompletionStage<Boolean> next(); |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns the current element if {@link #next()} yielded {@code true}. |
| 39 | + * Can be called multiple times between {@link #next()} calls. |
| 40 | + * @return the current element |
| 41 | + * @throws NoSuchElementException before the very first {@link #next()} or after {@link #next()} returned {@code false} |
| 42 | + */ |
| 43 | + @NonNull |
| 44 | + T current(); |
| 45 | + |
| 46 | + /** |
| 47 | + * Called when the stream ends or gets cancelled. Should be always invoked. |
| 48 | + * @return the stage you can await to cleanups to happen |
| 49 | + */ |
| 50 | + @NonNull |
| 51 | + CompletionStage<Void> close(); |
| 52 | +} |
0 commit comments