Java Code Examples for reactor.core.publisher.Mono#toFuture()
The following examples show how to use
reactor.core.publisher.Mono#toFuture() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerialTaskManagerWorker.java From james-project with Apache License 2.0 | 7 votes |
@Override public Mono<Task.Result> executeTask(TaskWithId taskWithId) { if (!cancelledTasks.remove(taskWithId.getId())) { Mono<Task.Result> taskMono = Mono.fromCallable(() -> runWithMdc(taskWithId, listener)).subscribeOn(taskExecutor); CompletableFuture<Task.Result> future = taskMono.toFuture(); runningTask.set(Tuples.of(taskWithId.getId(), future)); return Mono.using( () -> pollAdditionalInformation(taskWithId).subscribe(), ignored -> Mono.fromFuture(future) .onErrorResume(exception -> Mono.from(handleExecutionError(taskWithId, listener, exception)) .thenReturn(Task.Result.PARTIAL)), Disposable::dispose); } else { return Mono.from(listener.cancelled(taskWithId.getId(), taskWithId.getTask().details())) .then(Mono.empty()); } }
Example 2
Source File: CaffeineAsyncLoadingTest.java From promregator with Apache License 2.0 | 6 votes |
@Override public @NonNull CompletableFuture<Integer> asyncLoad(@NonNull String key, @NonNull Executor executor) { log.info(String.format("Request loading iteration %d for request %s", this.executionNumber, key)); Mono<Integer> result = null; synchronized(this) { result = Mono.just(executionNumber++); } result = result.subscribeOn(Schedulers.fromExecutor(executor)).cache(); if (this.executionNumber > 1) { result = Mono.error(new Error("Failure while async loading")); } return result.toFuture(); }
Example 3
Source File: MonoAdapter.java From graphql-spqr-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override public Object convertOutput(Mono<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //For subscriptions, Mono<T> (Publisher<T>) should be returned directly if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //For other operations it must be converted into a CompletableFuture<T> return original.toFuture(); }
Example 4
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<ListOrganizationsResponse> asyncLoad(@NonNull String key, @NonNull Executor executor) { Mono<ListOrganizationsResponse> mono = parent.retrieveOrgId(key) .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 5
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<ListOrganizationsResponse> asyncLoad(@NonNull String key, @NonNull Executor executor) { Mono<ListOrganizationsResponse> mono = parent.retrieveAllOrgIds() .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 6
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<ListSpacesResponse> asyncLoad(@NonNull CacheKeySpace key, @NonNull Executor executor) { Mono<ListSpacesResponse> mono = parent.retrieveSpaceId(key.getOrgId(), key.getSpaceName()) .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 7
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<ListSpacesResponse> asyncLoad(@NonNull String key, @NonNull Executor executor) { Mono<ListSpacesResponse> mono = parent.retrieveSpaceIdsInOrg(key) .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 8
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<ListApplicationsResponse> asyncLoad( @NonNull CacheKeyAppsInSpace key, @NonNull Executor executor) { Mono<ListApplicationsResponse> mono = parent.retrieveAllApplicationIdsInSpace(key.getOrgId(), key.getSpaceId()) .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 9
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<GetSpaceSummaryResponse> asyncLoad(@NonNull String key, @NonNull Executor executor) { Mono<GetSpaceSummaryResponse> mono = parent.retrieveSpaceSummary(key) .subscribeOn(Schedulers.fromExecutor(executor)) .cache(); return mono.toFuture(); }
Example 10
Source File: CaffeineAsyncLoadingTest.java From promregator with Apache License 2.0 | 5 votes |
@Override public @NonNull CompletableFuture<Integer> asyncLoad(@NonNull String key, @NonNull Executor executor) { log.info(String.format("Request loading iteration %d for request %s", this.executionNumber, key)); Mono<Integer> result = null; synchronized(this) { result = Mono.just(executionNumber++); } result = result.subscribeOn(Schedulers.fromExecutor(executor)); if (this.executionNumber > 1) { result = result.map( x-> { log.info(String.format("Starting to delay - iteration: %d", x)); return x; }).delayElement(Duration.ofMillis(200)) .map( x-> { log.info(String.format("Finished delaying - iteration: %d", x)); return x; }); } result = result.cache(); return result.toFuture(); }
Example 11
Source File: ReactiveAdapterFuture.java From alibaba-rsocket-broker with Apache License 2.0 | 4 votes |
@Override public Object fromPublisher(Mono<?> mono, Class<?> returnType, MutableContext mutableContext) { return mono.toFuture(); }
Example 12
Source File: MonoConverter.java From smallrye-reactive-streams-operators with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public <X> CompletionStage<X> toCompletionStage(Mono instance) { return instance.toFuture(); }