armeria
armeria copied to clipboard
Provide a way to load a value periodically or when it expires
AsyncLoader
can be useful in the following situations.
- When it is necessary to periodically read and update information from a file such as
resolv.conf
. - When data is not valid after a certain period of time, such as an OAuth 2.0 access token.
We already have an implementation for that. However, I hope to generalize it and add new features to use it in various cases. https://github.com/line/armeria/blob/4bfa172606e8059194ccdb2e9fd36c6d22ada786/oauth2/src/main/java/com/linecorp/armeria/client/auth/oauth2/AbstractOAuth2AuthorizationGrant.java#L118-L134
API proposal:
@FunctionalInterface
interface AsyncLoader<T> {
static <T> AsyncLoaderBuilder<T> builder(Supplier<CompletableFuture<T>> loader) {
return new AsyncLoaderBuilder<T>(loader);
}
CompletableFuture<T> get();
}
class AsyncLoaderBuilder<T> {
AsyncLoaderBuilder<T> expireAfterLoad(Duration duration) {
...
}
AsyncLoaderBuilder<T> expireIf(Predicate<T> predicate) {
...
}
}
oh interesting feature! may I handle this? I'll create PR within 4/22 🙇
Create PR #5590 :)