Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutiny integration with Kotlin Coroutines #403

Closed
imrabti opened this issue Dec 16, 2020 · 13 comments
Closed

Mutiny integration with Kotlin Coroutines #403

imrabti opened this issue Dec 16, 2020 · 13 comments
Labels
enhancement New feature or request noteworthy-feature Noteworthy feature
Milestone

Comments

@imrabti
Copy link

imrabti commented Dec 16, 2020

Is it possible to use Mutiny with Kotlin Coroutines ?

@jponge
Copy link
Member

jponge commented Dec 16, 2020

There is no specific integration. Do you have any use-case?

@imrabti
Copy link
Author

imrabti commented Dec 16, 2020

With Vertx there is the ability to run vertx code in the Coroutines scope as below :

CoroutineScope(vertx.dispatcher()).launch { // some vertx code }

Is it possible to achieve something similar ?

@jponge
Copy link
Member

jponge commented Dec 16, 2020

This has to be investigated

@nkhoshini
Copy link

You can convert a Uni to a CompletableFuture and then use the kotlinx-coroutines-jdk8 library to convert it to a coroutine
uni.subscribeAsCompletionStage().await() or
subscribeAsCompletionStage().asDeferred().await()

@heubeck
Copy link
Collaborator

heubeck commented Jan 4, 2021

Hey people,
also looking for a smooth way for using "the Quarkus stack" with Kotlin, mainly the reactive routes and of course Mutiny with a lots of Vert.x in between.

Where would be the right place for providing utility functions on Uni and Multi but also other Quarkus or even Vert.x types to make a Kotlin native developer experience by writing imperative (coroutine) code?

Obvious cases are:

  • suspend Uni.await
  • Multi.toChannel
  • suspending executors around RoutingExchange using the Vert.x coroutine dispatcher

Are these cases worth an own library, project by project? Or could it be part of the Quarkus Kotlin extension?

@cescoffier
Copy link
Contributor

For the 2 first items, we should be able to create a module in mutiny directly. For the last one, it would be in the Quarkus extension (not sure which one).

@heubeck
Copy link
Collaborator

heubeck commented Jan 5, 2021

Would love to start or contribute to a smallrye-mutiny-kotlin module.

How to organize this - since hopefully others will support too (@imrabti ?)?

Just create a fork open to write for everyone?

Since that new modul would give a good dependency for quarkus-kotlin, we can have a look to that afterwards.

@cescoffier
Copy link
Contributor

@heubeck Just create a fork and a PR opened to everyone.

@heubeck heubeck mentioned this issue Jan 6, 2021
7 tasks
@heubeck
Copy link
Collaborator

heubeck commented Jan 7, 2021

With PR #419 I'd like to implement the following "extensions":

  • Uni.awaitSuspending -> retrieve the item or raise the failure
  • Deferred.asUni -> create a Uni from that Deferred
  • Multi.asChannel -> stream the items or failure of the Multi to a newly created Channel
  • Channel.asMulti -> the other way around
  • Multi.asFlow -> Flows seem to fit better than Channels, so a Flow matches a Multi semantically
  • Flow.asMulti -> the other way around

Name of the functions is subject for discussion.

Please have a look in the PR for details and of cause reviews.

@cescoffier
Copy link
Contributor

I like the names!

@heubeck
Copy link
Collaborator

heubeck commented Jan 8, 2021

Had a talk with @bartwinski who suggested to use Flows instead of Channels (thanks for the hint).

Haven't worked with Flows yet but from the documentation they sounding much more like Multi / Reactive Streams than Channels which are more like a technique to communicate between coroutines.

Since I'm struggling with overflow issus in the Multi.asChannel implementation and Flows seem to solve buffering different, I'll change to Flow.

@heubeck
Copy link
Collaborator

heubeck commented Jan 10, 2021

PR #419 is now ready for review.

@heubeck
Copy link
Collaborator

heubeck commented Jan 13, 2021

@imrabti @bartwinski
As my implementation was accepted by the project, can you please test (after the upcoming Mutiny release) whether your needs are fulfilled and how it works out in real world projects, will do the same by myself.
I will welcome further improvement and additional function requests for come Mutiny and Coroutines close together.

@jponge jponge added this to the 0.13.0 milestone Jan 13, 2021
@jponge jponge added enhancement New feature or request noteworthy-feature Noteworthy feature labels Jan 13, 2021
@jponge jponge closed this as completed Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request noteworthy-feature Noteworthy feature
Projects
None yet
Development

No branches or pull requests

5 participants