async-object-stack

1.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i async-object-stack

Weekly Downloads

47

Version

1.0.0

License

MIT

Unpacked Size

77.3 kB

Total Files

54

Last publish

Collaborators

  • uhyo