18.3. Scala-like dynamic variable (gololang.DynamicVariable)

Golo has a DynamicVariable type that mimics the eponymous class from the Scala standard library.

A dynamic variable has inheritable thread-local semantics: updates to its value are confined to the current thread and its future child threads.

Given the following code:

let dyn = DynamicVariable("Foo")
println(dyn: value())

let t1 = Thread({
  dyn: withValue(666, {
    println(dyn: value())
  })
})

let t2 = Thread({
  dyn: withValue(69, {
    println(dyn: value())
  })
})

t1: start()
t2: start()
t1: join()
t2: join()
println(dyn: value())

one gets an output similar to:

Foo
69
666
Foo

with the 69 and 666 swapping order over runs.