darky / glorage

Gleam thread local storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

glorage

Package Version Hex Docs Erlang-compatible JavaScript-compatible

Gleam thread local storage

gleam add glorage
import glorage

pub fn main() {
  use <- glorage.run // init thread local storage

  inc(1) // 2

  inc(7) // 2, because it's cached inside thread local storage

  use n <- glorage.with(inc) // ability to get thread local storage cached value, n is 2
}

fn inc(n) {
  use <- glorage.once(inc) // make function cachable inside thread local storage
  n + 1
}

Further documentation can be found at https://hexdocs.pm/glorage.

Development

gleam run   # Run the project
gleam test  # Run the tests

About

Gleam thread local storage


Languages

Language:Gleam 75.0%Language:JavaScript 25.0%