armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Provide a way to load a value periodically or when it expires

Open ikhoon opened this issue 11 months ago • 2 comments

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) {
        ...
    }

}

ikhoon avatar Mar 15 '24 02:03 ikhoon

oh interesting feature! may I handle this? I'll create PR within 4/22 🙇

injae-kim avatar Mar 28 '24 01:03 injae-kim

Create PR #5590 :)

injae-kim avatar Apr 10 '24 17:04 injae-kim