-
Notifications
You must be signed in to change notification settings - Fork 56
Please provide ability to LDClient
in non-blocking manner
#281
Comments
I'm not sure which part of the code you were looking at, but that's not quite accurate. Please look at LDClient.java:270 and you will see that it conditionally blocks if the The advantage to doing it this way is that then you have an Once you have that object, assuming you do want to wait at some point for client initialization (since trying to evaluate flags will fail if it has not yet acquired the flag data), the method for that is |
Thanks! |
@t3hnar Currently there is not, but it's trivial in Java to spin a thread for such a task. One way to do that would look like this: final CompletableFuture<Boolean> clientInitialization = new CompletableFuture<>();
new Thread(() -> {
boolean result = client.getDataSourceStatusProvider()
.waitFor(DataSourceStatusProvider.State.VALID, Duration.ZERO);
clientInitialization.complete(result);
}).start(); There are two main reasons why we haven't implemented more asynchronous APIs in the Java SDK already. The main one is simply that we hadn't had any requests for them in the last two years (and prior to two years ago, we couldn't use most of the The other is that, unlike other platforms where there is a standard way to do asynchronous tasks and/or to manage thread pools, Java provides the building blocks but leaves a lot of leeway as to how you want those things to work, and it is tricky for library code to anticipate what will make sense for the application calling it. For instance, any caller who receives a |
Thanks for an example and comprehensive reply :) For us async api would be preferable as well as ability to control both CPU intensive and blocking ops thread pools to be used by the client. Not a blocker though… |
Reading source code I found that
new LDClient
blocks calling thread until we connect to backend and fetch data.Could you please provide something like
LDClient.create: Future[LDClient]
which does not block threads.The text was updated successfully, but these errors were encountered: