Closed orafaaraujo closed 2 years ago
Hello @orafaaraujo, thank you for reaching out to us with your suggestion.
To clarify, currently, Android SDK has an init
method that returns a Future<LDClient>
that doesn't have a timeout parameter, and it has an init
method that takes a timeout but returns just an LDClient
.
Do you mean you want something that is both returning a future and takes in a timeout argument?
Hello, @louis-launchdarkly Thank you for your reply.
Checking better the implementation I think the an init method that returns a Future<LDClient>
can work.
Do you recommend a way to wait for Future
be ready? I thought in something like this
val future: Future<LDClient>? = LDClient.init(application, config, user)
while(future?.isDone == false) {
Thread.sleep(300)
}
val clint: LDClient = LDClient.get()
But I personally would prefer having a listener, something like the LDStatusListener telling that the client is ready or if a timeout occurred to avoid blocking the implementation using a while
.
While on this topic, do you have plans to provide a Kotlin implementation with a suspend function? This would fit perfectly
Thank you once again
While we need to look more for your first question about a better init method, I can answer the second one first. Currently, we don't have any concrete plan for a Kotlin implementation. We are hearing a bit of interest about Kotlin so Kotlin is in our feature request backlog.
Would LDClient.registerAllFlagsListener
work for your use case? This will be called whenever flag data is received from LaunchDarkly.
If you just want to wait for the Future
to be completed, there is a .get
that takes a maximum time to wait on the Future
to be completed. So if you just want to wait on the Future
in a more granular way than the LDClient.init
method that takes a startWaitSeconds
provides (or for identify
), you can take a look at the implementation here for an idea of how to go about that. To avoid blocking the thread you're in, you could call Future.get
on a separate thread or coroutine that calls a callback when the .get
call completes.
Hope this helps, @gwhelanLD
Closing as there is a suggested workaround and no more comments from customers. If there is any other question, please feel free to open a new issue or contact our support. You can submit a support request by going here or by emailing support@launchdarkly.com.
Is your feature request related to a problem? Please describe. Hello,
I would like to know if it's possible to have a listener evaluate the feature flags as soon as the fetch is done. This could give us the flexibility to request some flags as soon as possible and know how long it was taken to fetch too. This listener could also provide us with a warning (or exception) about the timeout.
Describe the solution you'd like Something similar to what iOS has, in the
.start()
function. More details here https://docs.launchdarkly.com/sdk/client-side/ios#using-the-sdk-in-your-applicationDescribe alternatives you've considered I checked the Configuration section and the Subscribing to flag changes