Skip to content

Support CompletableFuture<> as return type of @Async methods [SPR-13128] #17719

@spring-projects-issues

Description

@spring-projects-issues

Thomas Darimont opened SPR-13128 and commented

Currently @Async annotated methods support to return Future<> result wrappers via AsyncResult<> it would be great if we would support CompletableFuture here as well.

I created a small example that adds the necessary functionality to AsyncExecutionInterceptor.

Usage:

	@Async
	public <T> CompletableFuture<T> asyncOperation(T input) {

		System.out.println("working...");
		LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(5));
		System.out.println("done.");
		
		return CompletableFuture.completedFuture(input);
	}

Consumer:

service.asyncOperation("test").thenAccept(System.out::println);

Reference URL: https://gist.github.com/thomasdarimont/197e92e537554634adbd

Issue Links:

Referenced from: commits dd4bc63, c41779f, 581ab18

0 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions