Class ExecutionContextManagerKt
-
- All Implemented Interfaces:
public final class ExecutionContextManagerKt
-
-
Method Summary
Modifier and Type Method Description final static <T extends Any> TwithContext(ExecutionContextManager $self, String key, Object value, Function0<T> action)Executes given action in a way that ExecutionContextManager.getFromCurrentContext for the given key returns given value until the action is done. final static <T extends Any> TwithContext(ExecutionContextManager $self, Map<String, Object> context, Function0<T> action)Similar to withContext(String, Any?)but applies the bulk parameters.final static <T extends Any> Function0<T>withCurrentContext(ExecutionContextManager $self, Function0<T> action)We might start processing in one thread and then continue in another thread, e.g. final static <T extends Any, R extends Any> Function1<T, R>withCurrentContext(ExecutionContextManager $self, Function1<T, R> action)-
-
Method Detail
-
withContext
final static <T extends Any> T withContext(ExecutionContextManager $self, String key, Object value, Function0<T> action)
Executes given action in a way that ExecutionContextManager.getFromCurrentContext for the given key returns given value until the action is done.
-
withContext
final static <T extends Any> T withContext(ExecutionContextManager $self, Map<String, Object> context, Function0<T> action)
Similar to
withContext(String, Any?)but applies the bulk parameters.
-
withCurrentContext
final static <T extends Any> Function0<T> withCurrentContext(ExecutionContextManager $self, Function0<T> action)
We might start processing in one thread and then continue in another thread, e.g. we might receive an event to process in one thread, queue and process it in a worker thread.
That way a context set in the initial thread is lost in the second thread and we need to re-configure it explicitly.
This method allows to decorate given action in a way that it's executed in the context which was active during this method's call time.
Sample:
executionContextManager.withContext("some-key", "some-value") { threadPool.submit(executionContextManager.withCurrentContext { println(executionContextManager.getFromCurrentContext("some-key")) // is guaranteed to print 'some-value' }) }
-
withCurrentContext
final static <T extends Any, R extends Any> Function1<T, R> withCurrentContext(ExecutionContextManager $self, Function1<T, R> action)
-
-
-
-