Class ExecutionContextManagerKt

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • 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'
            })
        }