Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala: Context & Observability

Scala: Context & Observability

Slides for The Art of Scala presentation in Warsaw on 25th May 2023

Michał Bednarz

May 25, 2023
Tweet

More Decks by Michał Bednarz

Other Decks in Programming

Transcript

  1. Scala:
    Context & Observability

    View full-size slide

  2. Context propagation
    explicit
    parameter
    implicit
    parameter

    View full-size slide

  3. Thread-safe state on
    JVM
    AtomicRef ThreadLocal
    Every thread has its own local copy
    of the state which is not visible to
    the others
    Shared state safely updated by many
    threads using optimistic concurrency (CAS)

    View full-size slide

  4. Context propagation
    on JVM
    ThreadLocal
    InheritableThreadLocal
    DynamicVariable

    View full-size slide

  5. Scope
    Lexical Dynamic
    Depends on location in source
    code
    Depends on method call
    graph

    View full-size slide

  6. Functional context
    propagation
    ReaderT / Kleisli
    (cats)
    IOLocal
    (cats-effect)
    Context functions
    (scala 3)

    View full-size slide

  7. Context propagation
    with cats-mtl
    Ask Local Stateful
    read-only environment
    effect
    dynamic scope
    effect
    shared mutable state
    effect

    View full-size slide

  8. Local + log4cats
    demo

    View full-size slide

  9. Local + log4cats + IOLocal
    demo

    View full-size slide

  10. Scala 3
    Context Functions

    View full-size slide

  11. linktr.ee/mbednarz

    View full-size slide