-
I’m very comfortable with vert.x’s Future/Promise and fairly new to Mutiny. Looking for a guide along the lines of “When you do this with a future, do that with Uni/Multi” I frequently have code like: somethingFutureA()
.compose(this::takeAmakeB)
.compose(this::takeBmakeC)
.onSuccess(ctx::end); Or List<Future<?>> allTheThings = kickoffAllThings();
Future.all(allTheThings)
.onSuccess(result -> {…})
.onFailure(ShitHappens::noFuture); Methods I design often look like this Future<SomeResult> attemptSomeResult(SomeData parameter) {
Promise<SomeResult> outcome = Promise.promise();
// do stuff here
if (success) {
promise.complete(aSomeResultObject);
} else {
promise.fail(errorCondition);
}
return Promise.future();
} What would be the Mutiny way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
/cc @Ladicek (smallrye), @cescoffier (mutiny), @jmartisk (smallrye), @jponge (mutiny), @phillip-kruger (smallrye), @radcortez (smallrye) |
Beta Was this translation helpful? Give feedback.
-
So far my impression:
But I’m sure there are sufficient subtleties to trip over. I’m especially curious about how to implement Subscribe to a Multi looks very much like an Observable/Observer. I wonder how could multiple subscribers subscribe to a Multi, receiving the same items |
Beta Was this translation helpful? Give feedback.
Coming from Vert.x the main difference of a
Uni
vs aFuture
is that aUni
needs to be subscribed to before the actual action is triggered, whereas you can't control when a Vert.x future starts. You will find lots of composition operations to transform values, compose asynchronous results, handle errors, etc.You might want to start with https://smallrye.io/smallrye-mutiny/latest/tutorials/hello-mutiny/ and look over the documentation here.
You might also look at the samples in https://github.com/smallrye/smallrye-mutiny/tree/main/workshop-examples
Hope it helps!