1.0.0 • Published 5 months ago

async-object-stack v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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.

Reference

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

1.0.0

5 months ago

1.0.0-beta.1

5 months ago

1.0.0-beta.0

5 months ago