Should I be using completableFuture in kotlin or i...
# getting-started
y
j
I don't think
: CompletionStage<T> by CompletableFuture()
does what you think it does. You're making
RestExecutableRestAction
implement
CompletionStage<T>
by delegating all the implementations to a new instance of
CompletableFuture
that has nothing to do with the
completableFuture
property.
Now to reply to the initial question, it's ok to use
CompletableFuture
in Kotlin, but it is usually more idiomatic to use
suspend
functions and coroutines
y
Can you give me an example please
@Joffrey
j
Also, your actions hierarchy here is kinda broken because you're not using the same instance of
CompletableFuture
within the same action. For instance
RestExecutableRestAction
provides accessors for its own
completableFuture
property, and it extends
ExtendableAction
which has a separate
completableFuture
property. Using
complete
on
RestExecutableRestAction
will not complete the same future and will have no effect on the
execute
functions. All in all, the whole hierarchy doesn't seem necessary at all. Why not use
CompletableFuture
directly in your case instead of this custom hierarchy?
About giving an example, I just meant to use
suspend fun something(...): SomeType
whenever you need to represent an async operation. You probably don't need any abstraction on top of that. But the coroutines world is its own thing to learn, and this cannot fit in a Slack thread. I suggest to do some reading about them first.
y
Ok
Will do so
I wanted to have my own get method
Instead of being called get it’s called execute which sounds more appropriate