Java Code Examples for reactor.core.publisher.Mono#toFuture()

The following examples show how to use reactor.core.publisher.Mono#toFuture() . These examples are extracted from open source projects. 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
@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
@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
@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
@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
@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
@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
@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
@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
@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
@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
@Override
public Object fromPublisher(Mono<?> mono, Class<?> returnType, MutableContext mutableContext) {
    return mono.toFuture();
}
 
Example 12
@SuppressWarnings("unchecked")
@Override
public <X> CompletionStage<X> toCompletionStage(Mono instance) {
    return instance.toFuture();
}