Skip to content

Migrate client.identify() calls to use CompletableFuture<T> #277

@erawhctim

Description

@erawhctim

Is your feature request related to a problem? Please describe.
It'd be nice if the LD SDK used CompletableFuture<T> (or if the internal Future impl. types LDAwaitFuture<T>, etc, implemented CompletionStage<T>) so that Kotlin apps could leverage the built-in conversion functions from kotlinx.coroutines.future to convert Future's to suspend fn's.

Right now, clients have to do this conversion manually:

suspend fun identifyInternal(): Unit = suspendCancellableCoroutine { continuation ->
  val future = client.identify(/* build a context */)
  continuation.invokeOnCancellation { future.cancel(/* mayInterruptIfRunning = */ true) }

  try {
    future.get()
    continuation.resume(Unit)
  } catch (e: ExecutionException) {
    continuation.resumeWithException(e.cause ?: e)
  } catch (e: InterruptedException) {
    continuation.resumeWithException(e)
  }
}

Ultimately it's not a ton of work to do this manually, but it'd be convenient to eliminate some of this boilerplate conversion code (if supporting CompletableFuture<T> is easy to do on your end).

Describe the solution you'd like
Supporting one of the above types. This would allow Kotlin clients to use kotlinx conversion functions like this:

suspend fun identifyInternal(): Unit {
  return client.identify(/* build a context */).await()
}

Describe alternatives you've considered
Continue doing the hand-written/manual conversion listed above.

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions