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

com.gs.api.accelrx.context.rxjava3.ContextPropagatorOnMaybeAssemblyAction Maven / Gradle / Ivy

The newest version!
package com.gs.api.accelrx.context.rxjava3;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.MaybeObserver;
import io.reactivex.rxjava3.functions.Function;

import java.util.concurrent.Executor;

@SuppressWarnings("rawtypes")
public class ContextPropagatorOnMaybeAssemblyAction implements Function {

    private final ThreadContext threadContext;

    public ContextPropagatorOnMaybeAssemblyAction(ThreadContext threadContext) {
        this.threadContext = threadContext;
    }

    @Override
    @SuppressWarnings({"rawtypes", "unchecked"})
    public Maybe apply(Maybe maybe) throws Throwable {
        return new ContextPropagatorMaybe<>(maybe, threadContext.currentContextExecutor());
    }

    private static final class ContextPropagatorMaybe extends Maybe {

        private final Maybe source;
        private final Executor contextExecutor;

        public ContextPropagatorMaybe(Maybe single, Executor contextExecutor) {
            this.source = single;
            this.contextExecutor = contextExecutor;
        }

        @Override
        protected void subscribeActual(@NonNull MaybeObserver observer) {
            contextExecutor.execute(() -> source.subscribe(observer));
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy