async-object-stack
v1.0.0
Published
Stacked objects in async call stack
Downloads
910
Readme
async-object-stack
A wrapper of AsyncLocalStorage that keeps a stack of objects. Supports the using
syntax to automatically pop objects from the stack when the current scope ends.
Primary use case is creating a nice API for structural logging. See Structural Logging Example.
Installation
npm install async-object-stack
Example
See also: Structural Logging Example.
import { createAsyncObjectStack } from 'async-object-stack';
const stack = createAsyncObjectStack();
console.log(stack.render()); // {}
using guard = stack.push({ pika: "chu" });
console.log(stack.render()); // { pika: "chu" }
{
using guard2 = stack.push({ bulba: "saur" });
console.log(stack.render()); // { pika: "chu", bulba: "saur" }
}
console.log(stack.render()); // { pika: "chu" }
License
MIT