A Thread-local storage (TLS) like Map implementation, base on node async hooks, support nodejs & typescript
- #### thread local support for nodejs & typescript
- #### named scope & chain support , easily to get closest forefather scope
- #### browser or lower version of node support if provided an async-hooks implementation with constructor
install
npm install async-hooks-map
import
// typescript;// javascriptconst AsyncHookMap =
Usage
typescript:
// import asyncHookMap from 'async-hooks-map' // import global instance which is lazy initialize // Object.defineProperty(exports, 'default', { // get () {} // }) Promise.resolve.then})
Api:
tips
- closest(name:string) contains this and parent(name?:string) not closest will throw when cant find the scope and parent() will return undefined
- A async scope can have multiple names
- Top async scope is named 'root' by default