Package pl.morgwai.base.guice.scopes
Class ContextBinder
- java.lang.Object
-
- pl.morgwai.base.guice.scopes.ContextBinder
-
public class ContextBinder extends Object
Binds closures to contexts that were active at the time of binding. This can be used to transfer contexts when passing callbacks to async functions:class MyComponent { @Inject ContextBinder ctxBinder; void methodThatCallsSomeAsyncMethod(...) { // other code here... someAsyncMethod(arg1, ... arN, ctxBinder.bindToContext((callbackParam) -> { // callback code here... })); } }
Deriving libs should bind this class in their main
Module
.
-
-
Constructor Summary
Constructors Constructor Description ContextBinder(List<ContextTracker<?>> trackers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ContextBoundRunnable
bindToContext(Runnable toBind)
<T,U>
ContextBoundBiConsumer<T,U>bindToContext(BiConsumer<T,U> toBind)
<T> ContextBoundConsumer<T>
bindToContext(Consumer<T> toBind)
-
-
-
Constructor Detail
-
ContextBinder
public ContextBinder(List<ContextTracker<?>> trackers)
-
-
Method Detail
-
bindToContext
public ContextBoundRunnable bindToContext(Runnable toBind)
-
bindToContext
public <T> ContextBoundConsumer<T> bindToContext(Consumer<T> toBind)
-
bindToContext
public <T,U> ContextBoundBiConsumer<T,U> bindToContext(BiConsumer<T,U> toBind)
-
-