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

io.quarkus.oidc.runtime.BlockingTaskRunner Maven / Gradle / Ivy

Go to download

Secure your applications with OpenID Connect Adapter and IDP such as Keycloak

There is a newer version: 3.18.0.CR1
Show newest version
package io.quarkus.oidc.runtime;

import java.util.function.Consumer;
import java.util.function.Supplier;

import io.quarkus.oidc.OidcRequestContext;
import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.runtime.ExecutorRecorder;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.subscription.UniEmitter;

public class BlockingTaskRunner implements OidcRequestContext {
    public Uni runBlocking(Supplier function) {
        return Uni.createFrom().deferred(new Supplier>() {
            @Override
            public Uni get() {
                if (BlockingOperationControl.isBlockingAllowed()) {
                    try {
                        return Uni.createFrom().item(function.get());
                    } catch (Throwable t) {
                        return Uni.createFrom().failure(t);
                    }
                } else {
                    return Uni.createFrom().emitter(new Consumer>() {
                        @Override
                        public void accept(UniEmitter uniEmitter) {
                            ExecutorRecorder.getCurrent().execute(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        uniEmitter.complete(function.get());
                                    } catch (Throwable t) {
                                        uniEmitter.fail(t);
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy