# CompletableFuture -\> Deferred

**URL:** <https://discuss.kotlinlang.org/t/completablefuture-deferred/6857>\
**Category:** Uncategorized\
**Created:** [March 2, 2018, 7:41pm UTC](https://discuss.kotlinlang.org/t/completablefuture-deferred/6857 "2018-03-02T19:41:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elifarley](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/elifarley/32/1804_2.png) [@elifarley](https://discuss.kotlinlang.org/u/elifarley)\
**Post date:** [March 2, 2018, 7:41pm UTC](https://discuss.kotlinlang.org/t/completablefuture-deferred/6857/1 "2018-03-02T19:41:30Z")

</div>

I have to use a Java lib (ArangoDB async driver) with methods returning CompletableFuture instances.

I’m creating a façade and I’d like to avoid exposing CompletableFuture. Instead, I want to expose Deferred instances.

My first attempt looks like this:

> fun find(id: String): Deferred = async {  
> val document: CompletableFuture = collection.getDocument(id, c)  
> document.await()  
> }

Is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [March 2, 2018, 8:21pm UTC](https://discuss.kotlinlang.org/t/completablefuture-deferred/6857/2 "2018-03-02T20:21:56Z")

</div>

> <https://github.com/Kotlin/kotlinx.coroutines/pull/263>
>
> Hello,
> 
> This PR Implements \`fun \<T\> CompletionStage\<T\>.asDeferred(): Deferred\<…T\>\` as proposed by @elizarov in #262.
> 
> Let me know what you think about it.

---

<div class="post-metadata">

**Author:** ![elifarley](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/elifarley/32/1804_2.png) [@elifarley](https://discuss.kotlinlang.org/u/elifarley)\
**Post date:** [March 2, 2018, 8:41pm UTC](https://discuss.kotlinlang.org/t/completablefuture-deferred/6857/3 "2018-03-02T20:41:05Z")

</div>

That’s great! When should it be available in Maven repos ?

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [March 5, 2018, 3:44pm UTC](https://discuss.kotlinlang.org/t/completablefuture-deferred/6857/4 "2018-03-05T15:44:39Z")

</div>

> **[Release 0.22.4 · Kotlin/kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.22.4)**
>
> JS: Publish to NPM (see #229).
> JS: Use node-style dispatcher on ReactNative (see #236).
> jdk8 integration improvements:
> 
> Added conversion from CompletionStage to Deferred (see #262, PR by @jcornaz)....
