vsilaev / tascalate-async-await

Async / Await asynchronous programming model for Java versions 1.8 - 23; similar to the functionality available in C# 5. The implementation is based on continuations for Java (see my other projects).
BSD 2-Clause "Simplified" License
104 stars 12 forks source link

Interfaces question #7

Closed auriium2 closed 2 years ago

auriium2 commented 2 years ago

Does async await work with interfaces? If so, would i make @async the interface method or the implementing class?

vsilaev commented 2 years ago

It re-transforms only methods with bodies. So you have to follow this pattern:

  1. Interface
    public interface MyInterface {
    abstract public CompletionStage<String> myAsyncMethod();
    }
  2. Implementation class:
    
    public class MyClass implements MyInterface {
    @Overrides
    @async public CompletionStage<String> myAsyncMethod() {
       ...
       return async(myResult);
    }
    }