Skip to content

Instantly share code, notes, and snippets.

@leandrob13
Created February 24, 2018 23:33
Show Gist options
  • Save leandrob13/34dbee5619020171dc1d1b7c93b4372b to your computer and use it in GitHub Desktop.
Save leandrob13/34dbee5619020171dc1d1b7c93b4372b to your computer and use it in GitHub Desktop.
import monix.eval.Task
import monix.execution.{CancelableFuture, Scheduler}
case class TracingIds(ids: Map[String, String]) extends TracingContext {
import TracingIds._
def asCurrent[T](t: Task[T]): Task[T] =
TracingIds.bind(this)(t)
def execute[T](t: Task[T])(implicit sch: Scheduler, opt: Task.Options): CancelableFuture[T] = {
try local.bind(this)(t).runAsyncOpt
finally local.write(default).coeval.value
}
}
object TracingIds extends TracingContextCompanion[TracingIds] {
val default = TracingIds(Map.empty[String, String])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment