Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a completed instance of org.springframework.util.concurrent.ListenableFuture

Tags:

java

spring

How to create a dummy instance of org.springframework.util.concurrent.ListenableFuture?

It should represents a completed task with a given result.

like image 442
Mateusz Stefek Avatar asked Apr 22 '26 23:04

Mateusz Stefek


1 Answers

Assuming String result, you can use following:

    String result = "result";
    ListenableFuture<String> future = new AsyncResult<>(result);
    String dummy = future.get();

However, if you need, any object can be wrapped in AsyncResult.

like image 135
Oleksii Zghurskyi Avatar answered Apr 25 '26 04:04

Oleksii Zghurskyi