šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

cls-bluebird

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cls-bluebird

Make bluebird work with the continuation-local-storage module.

2.1.0
latest
Source
npm
Version published
Weekly downloads
273K
9.71%
Maintainers
2
Weekly downloads
Ā 
Created

What is cls-bluebird?

The cls-bluebird npm package is a utility that integrates continuation-local storage (CLS) with the Bluebird promise library. This allows you to maintain context across asynchronous operations, which is particularly useful for things like request tracing, logging, and managing user sessions.

What are cls-bluebird's main functionalities?

Integrate CLS with Bluebird

This feature allows you to integrate CLS with Bluebird promises. The code sample demonstrates how to create a namespace, integrate it with Bluebird, and maintain context across asynchronous operations.

const cls = require('cls-hooked');
const ns = cls.createNamespace('myNamespace');
const Promise = require('bluebird');
require('cls-bluebird')(ns, Promise);

ns.run(() => {
  ns.set('key', 'value');
  Promise.resolve().then(() => {
    console.log(ns.get('key')); // Outputs: 'value'
  });
});

Maintain context in nested promises

This feature ensures that the context is maintained even in nested promises. The code sample shows how the context set in the outer promise is accessible in the inner promise.

const cls = require('cls-hooked');
const ns = cls.createNamespace('myNamespace');
const Promise = require('bluebird');
require('cls-bluebird')(ns, Promise);

ns.run(() => {
  ns.set('key', 'value');
  Promise.resolve().then(() => {
    return Promise.resolve().then(() => {
      console.log(ns.get('key')); // Outputs: 'value'
    });
  });
});

Other packages similar to cls-bluebird

Keywords

continuation-local-storage

FAQs

Package last updated on 09 Dec 2017

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