|
14 | 14 | package io.reactivex.rxjava4.core; |
15 | 15 |
|
16 | 16 | import java.util.*; |
17 | | -import java.util.concurrent.*; |
18 | | -import java.util.function.Function; |
| 17 | +import java.util.concurrent.CompletionStage; |
19 | 18 |
|
20 | | -import io.reactivex.rxjava4.annotations.*; |
| 19 | +import io.reactivex.rxjava4.annotations.NonNull; |
21 | 20 | import io.reactivex.rxjava4.disposables.*; |
| 21 | +import io.reactivex.rxjava4.internal.util.AwaitCoordinator; |
22 | 22 |
|
23 | 23 | /** |
24 | 24 | * A realized stream which can then be consumed asynchronously in steps. |
|
31 | 31 | * TODO proper docs |
32 | 32 | * @since 4.0.0 |
33 | 33 | */ |
34 | | -public interface Streamer<@NonNull T> extends AutoCloseable { |
| 34 | +public interface Streamer<@NonNull T> extends AutoCloseable, AwaitCoordinator { |
35 | 35 |
|
36 | 36 | // oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo |
37 | 37 | // API |
@@ -195,79 +195,4 @@ default void awaitFinish() { |
195 | 195 | default void awaitFinish(@NonNull DisposableContainer cancellation) { |
196 | 196 | await(finish(cancellation), cancellation); |
197 | 197 | } |
198 | | - |
199 | | - // oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo |
200 | | - // ASYNC/AWAIT "Language" keyword implementations |
201 | | - // oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo |
202 | | - |
203 | | - /** |
204 | | - * The {@code await} keyword for async/await. |
205 | | - * @param <T> the type of the returned value if any. |
206 | | - * @param stage the stage to await virtual-blockingly |
207 | | - * @return the awaited value |
208 | | - */ |
209 | | - @Nullable |
210 | | - static <T> T await(@NonNull CompletionStage<T> stage) { |
211 | | - return await(stage, null); |
212 | | - } |
213 | | - |
214 | | - /** |
215 | | - * The cancellable {@code await} keyword for async/await. |
216 | | - * @param <T> the type of the returned value if any. |
217 | | - * @param stage the stage to await virtual-blockingly |
218 | | - * @param canceller the container that can trigger a cancellation on demand |
219 | | - * @return the awaited value |
220 | | - */ |
221 | | - @Nullable |
222 | | - static <T> T await(@NonNull CompletionStage<T> stage, @Nullable DisposableContainer canceller) { |
223 | | - var f = stage.toCompletableFuture(); |
224 | | - if (canceller == null) { |
225 | | - return f.join(); |
226 | | - } |
227 | | - var d = Disposable.fromFuture(f, true); |
228 | | - try (var _ = canceller.subscribe(d)) { |
229 | | - return f.join(); |
230 | | - } |
231 | | - } |
232 | | - |
233 | | - /** |
234 | | - * Runs a function while turning it into a CompletionStage with a canceller supplied too. |
235 | | - * @param <U> the return type of the function |
236 | | - * @param function the function to apply |
237 | | - * @param canceller the canceller to use |
238 | | - * @param executor the executor to use |
239 | | - * @return the new stage |
240 | | - */ |
241 | | - static <U> CompletionStage<U> runStage(Function<DisposableContainer, U> function, |
242 | | - DisposableContainer canceller, Executor executor) { |
243 | | - var loopback = new SerialDisposable(); |
244 | | - canceller.add(loopback); |
245 | | - |
246 | | - // new Exception().printStackTrace(); |
247 | | - |
248 | | - var f = CompletableFuture.supplyAsync(() -> { |
249 | | - try { |
250 | | - return function.apply(canceller); |
251 | | - } finally { |
252 | | - canceller.delete(loopback); |
253 | | - } |
254 | | - }, executor); |
255 | | - |
256 | | - var d = Disposable.fromFuture(f, true); |
257 | | - loopback.replace(d); |
258 | | - |
259 | | - return f; |
260 | | - } |
261 | | - |
262 | | - /** |
263 | | - * Runs a function while turning it into a CompletionStage with a canceller supplied too. |
264 | | - * @param <U> the return type of the function |
265 | | - * @param function the function to apply |
266 | | - * @param canceller the canceller to use |
267 | | - * @return the new stage |
268 | | - */ |
269 | | - static <U> CompletionStage<U> runStage(Function<DisposableContainer, U> function, |
270 | | - DisposableContainer canceller) { |
271 | | - return runStage(function, canceller, Executors.newVirtualThreadPerTaskExecutor()); |
272 | | - } |
273 | 198 | } |
0 commit comments