Slides for The Art of Scala presentation in Warsaw on 25th May 2023
Scala:Context & Observability
View Slide
Context propagationexplicitparameterimplicitparameter
Thread-safe state onJVMAtomicRef ThreadLocalEvery thread has its own local copyof the state which is not visible tothe othersShared state safely updated by manythreads using optimistic concurrency (CAS)
Context propagationon JVMThreadLocalInheritableThreadLocalDynamicVariable
ScopeLexical DynamicDepends on location in sourcecodeDepends on method callgraph
Functional contextpropagationReaderT / Kleisli(cats)IOLocal(cats-effect)Context functions(scala 3)
Context propagationwith cats-mtlAsk Local Statefulread-only environmenteffectdynamic scopeeffectshared mutable stateeffect
Local + log4catsdemo
Local + log4cats + IOLocaldemo
Scala 3Context Functions
linktr.ee/mbednarz