All Downloads are FREE. Search and download functionalities are using the official Maven repository.

_08_misc._03_Context Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:2.7.0-RC4
package _08_misc;

import java.util.List;

import io.smallrye.mutiny.Context;
import io.smallrye.mutiny.Multi;

public class _03_Context {

    public static void main(String[] args) {
        System.out.println("⚡️ Using subscription-bound contexts");

        Context context = Context.of("foo", 123, "bar", "abc-123-def");

        List list = Multi.createFrom().range(1, 10)
                .withContext((multi, ctx) -> multi.onItem().invoke(n -> ctx.put("n", n)))
                .select().where(n -> n % 2 == 0)
                .withContext(
                        (multi, ctx) -> multi.onItem().transform(n -> n + "::" + ctx.get("n") + " @foo -> " + ctx.get("foo")))
                .collect().asList()
                .awaitUsing(context).indefinitely();

        System.out.println(list);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy