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

io.reactiverse.reactivecontexts.propagators.rxjava2.ContextPropagatorOnSingleAssemblyAction Maven / Gradle / Ivy

package io.reactiverse.reactivecontexts.propagators.rxjava2;

import io.reactiverse.reactivecontexts.core.Context;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.functions.Function;

public class ContextPropagatorOnSingleAssemblyAction implements Function {

	@Override
	public Single apply(Single t) throws Exception {
		return new ContextPropagatorSingle(t);
	}

	public class ContextPropagatorSingle extends Single {

		private Single source;
		private Object[] context;

		public ContextPropagatorSingle(Single t) {
			this.source = t;
			this.context = Context.capture();
		}

		@Override
		protected void subscribeActual(SingleObserver observer) {
			Object[] previousContext = Context.install(context);
			try {
				source.subscribe(observer);
			}finally {
				Context.restore(previousContext);
			}
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy