Current section
Files
Jump to
Current section
Files
src/booklet_ffi.mjs
const cache = new Map()
let last_key = 1
export function make(default_value) {
const key = last_key++;
if (key >= Number.MAX_SAFE_INTEGER) {
throw new globalThis.Error("booklet: system limit reached.")
}
cache.set(key, default_value)
return key
}
export function get(key) {
return cache.get(key)
}
export function update(key, updater) {
const new_value = updater(cache.get(key));
cache.set(key, new_value);
return new_value;
}