Local in scala.concurrent

54 views
Skip to first unread message

mikael....@magine.com

unread,
Jun 21, 2016, 9:51:40 AM6/21/16
to scala-user
Does scala.concurrent have something equivalent to Local in Twitter utils (https://twitter.github.io/util/docs/#com.twitter.util.Local)?

In other words, is there any way to have something like Java's ThreadLocal which follows the application flow (rather than JVM threads) when using scala.concurrent.Future?

Jasper-M

unread,
Jun 21, 2016, 10:36:50 AM6/21/16
to scala-user
I think http://www.scala-lang.org/api/2.11.8/#scala.util.DynamicVariable is a wrapper around ThreadLocal.

Op dinsdag 21 juni 2016 15:51:40 UTC+2 schreef mikael....@magine.com:

mikael....@magine.com

unread,
Jun 23, 2016, 1:46:50 PM6/23/16
to scala-user
As far as I can see, this does not integrate into Scala's Futures like Twitter's Local do (into Twitter's Futures).

Naftoli Gugenheim

unread,
Jun 26, 2016, 9:23:47 PM6/26/16
to mikael....@magine.com, scala-user


On Tue, Jun 21, 2016, 9:51 AM <mikael....@magine.com> wrote:
Does scala.concurrent have something equivalent to Local in Twitter utils (https://twitter.github.io/util/docs/#com.twitter.util.Local)?

In other words, is there any way to have something like Java's ThreadLocal which follows the application flow (rather than JVM threads) when using scala.concurrent.Future?

Not familiar with Local, but in general in Scala the way to pass things using statically rather than dynamically scoped values is to use parameters, making them implicit when appropriate (e.g., writing then out makes the code less readable, and the types distinguish them well enough).


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Armak

unread,
Jun 28, 2016, 4:49:12 AM6/28/16
to Naftoli Gugenheim, mikael....@magine.com, scala-user
For something like Local that follows execution wherever it goes, you would have to pass the implicit parameter to every function ever called (or, at least, every higher order function). That's clearly impractical.

Daniel Armak

Viktor Klang

unread,
Jun 28, 2016, 6:00:50 AM6/28/16
to Daniel Armak, Naftoli Gugenheim, mikael....@magine.com, scala-user
One also needs to remember that that Local propagation needs to be done at all Thread-jumps otherwise things go awry. Since there are tons of libraries which do not support Locals, it does seem like a very fragile solution.

:/
Cheers,

mikael....@magine.com

unread,
Jun 28, 2016, 9:36:41 AM6/28/16
to scala-user
I created an issue about this: https://issues.scala-lang.org/browse/SI-9835


On Tuesday, June 21, 2016 at 3:51:40 PM UTC+2, mikael....@magine.com wrote:
Reply all
Reply to author
Forward
0 new messages