New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async-cls

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-cls

dead simple continuation local storage using async hooks

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

async-cls

dead simple "continuation-local storage" with Node async_hooks

npm travis standard

Install

npm install async-cls

Usage

continuation local storage allows you to implicitly make values available to an asynchronous chain of code. Multiple asynchronous chains of the same code can be running simultaneously, and each will only get access to its own value.

var cls = require('async-cls')
var express = require('express')

var userContext = cls()

var app = express()
app.get('/', function (req, res) {
  userContext.current = req.user
  // you can do any async operation, like filesystem access or waiting for Promises
  // to resolve
  setTimeout(function () {
    respond(res)
  })
})

function respond (res) {
  // `userContext.current` will return the `req.user` value that was set in this async call stack
  res.json({ userId: userContext.current.id })
}

API

context = cls()

Create a new context. A context can hold a single JavaScript value per async context.

context.current = value

Set the value for this async context (call stack).

context.current

Get the value for this async context.

context.destroy()

Destroy the context, removing its async_hook and cleaning up any context values. Accessing context.current after the context has been destroyed will return undefined.

License

Apache-2.0

FAQs

Package last updated on 23 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc