Async Argument
To parse arguments asynchronously you can choose from three different ways:
- Add
@Async
annotation before argument - Use argument with the
CompletableFuture<T>
type - Create custom
ArgumentResolver
with an async result (Coming Soon)
1. @Async
annotation
You need to use the @Async
annotation on the argument:
Java
@Command(name = "user")
public class UserCommand {
@Execute(name = "load")
void execute(@Async @Arg User argument) {
System.out.print("This message is triggered in the main thread!");
}
}
WARNING
The @Async
annotation on the argument will parse the argument asynchronously, but the command will be executed in the main thread.
2. CompletableFuture<T>
type
Using CompletableFuture<T>
is more complicated:
java
@Command(name = "user")
public class UserCommand {
@Execute(name = "load")
void execute(@Arg CompletableFuture<User> argument) {
System.out.print("This message is triggered in the main thread!");
argument.whenComplete((user, error) -> {
if (error != null) {
return;
}
System.out.print("This message is triggered asynchronously!");
});
}
}