Skip to content

A Node.js library that implements Continuation-Local Storage for Node 10+

License

Notifications You must be signed in to change notification settings

hellocomet/hello-cls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hello-cls

Version Build status Codecov JavaScript Style Guide

A Node.js library that implements Continuation-Local Storage for Node 10+

Install & Requirements

npm i hello-cls
or
yarn add hello-cls

How to use

const { namespace } = require('hello-cls')

const context = namespace.initContext()

// I can't get a value from the namespace if one has not been set yet
console.log(namespace.get('beer'))
// -> undefined

// I can set a value to a given key on the namespace
namespace.set('beer', '🍺')

// I can get a value from the namespace
console.log(namespace.get('beer'))
// -> '🍺'

// close with 'true' will flush state immediately
context.close(true)

// I can't get a value from the namespace if the context is closed
console.log(namespace.get('beer'))
// -> null

Made with ❤️ at comet