pallet.core.thread-local documentation

Provides a thread local place, using a dynamic var.

A thread local place can be given a value using with-thread-locals. It is an error to use with-thread-locals if the thread local already has a value.

The current value of the thread local is found with thread-local.

The current value of the thread local can be set with thread-local!. It is an error to set the value on a thread other than the one used to provide the initial value using with-thread-locals.

 (def ^:dynamic *tl*)

 (with-thread-locals [*t1* {}]
  (assert (= (thread-local *tl*) {}))
  (thread-local! *tl* {:a 1})
  (assert (= (thread-local *tl*) {:a 1})))

thread-local

fn

[sym]

Get the value of the thread local

thread-local!

fn

[sym value]

Reset the value of a thread local

with-thread-locals

macro

[bindings & body]

Assign an initial value to a thread local.