2

ThreadLocal-like class that keeps its value through Future.map/Future.flatMap is extremely useful to trace request, for example, for logging.

Is there existing abstraction in Scala library to serve as such Local?

Is there a way to attach such Local to ExecutionContext.global?

Sergey Alaev
  • 3,851
  • 2
  • 20
  • 35

1 Answers1

1

Here is a blog entry where someone describes using scala.util.DynamicVariable and a custom scala.concurrent.ExecutionContext to capture and manage it: http://stevenskelton.ca/threadlocal-variables-scala-futures/

And here's is another blog entry describing how Hootsuite does something similar: http://code.hootsuite.com/logging-contextual-info-in-an-asynchronous-scala-application/

Rob Starling
  • 3,868
  • 3
  • 23
  • 40