Skip to content

Instantly share code, notes, and snippets.

@leandrob13
Created February 24, 2018 23:18
Show Gist options
  • Save leandrob13/3b87c9018f97be38e76c596491aa2bc4 to your computer and use it in GitHub Desktop.
Save leandrob13/3b87c9018f97be38e76c596491aa2bc4 to your computer and use it in GitHub Desktop.
import monix.eval.{Task, TaskLocal}
import monix.execution.{CancelableFuture, Scheduler}
trait TracingContext {
def asCurrent[T](t: Task[T]): Task[T]
def execute[T](t: Task[T])(implicit sch: Scheduler, opt: Task.Options): CancelableFuture[T]
}
trait TracingContextCompanion[T <: TracingContext] {
val default: T
val local: TaskLocal[T] = TaskLocal(default)
def current: Task[T] =
local.read.map(Option(_).getOrElse(default))
def bind[R](t: T)(task: Task[R]): Task[R] =
local.bind(t)(task)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment