Gathering detailed insights and metrics for cls-bluebird-jl
Gathering detailed insights and metrics for cls-bluebird-jl
npm install cls-bluebird-jl
Typescript
Module System
Node Version
NPM Version
71.6
Supply Chain
97
Quality
74.7
Maintenance
100
Vulnerability
100
License
JavaScript (99.7%)
Shell (0.3%)
Total Downloads
1,572
Last Day
1
Last Week
3
Last Month
16
Last Year
269
1 Stars
208 Commits
2 Watching
6 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.0-jl
Package Id
cls-bluebird-jl@2.0.0-jl
Size
10.20 kB
NPM Version
3.10.5
Node Version
6.3.1
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
-25%
3
Compared to previous week
Last month
-11.1%
16
Compared to previous month
Last year
14.5%
269
Compared to previous year
Patch bluebird for continuation-local-storage support.
Compatible with bluebird v2.x and v3.x. Tests cover both versions.
clsBluebird( ns [, Promise] )
1var cls = require('continuation-local-storage'); 2var ns = cls.createNamespace('myNamespace'); 3 4var Promise = require('bluebird'); 5var clsBluebird = require('cls-bluebird'); 6 7clsBluebird( ns ); 8// Promise is now patched to maintain CLS context
The above patches the "global" instance of bluebird. So anywhere else in the same app that calls require('bluebird')
will get the patched version (assuming npm resolves to the same file).
To patch a particular instance of bluebird:
1var Promise = require('bluebird'); 2var clsBluebird = require('cls-bluebird'); 3 4clsBluebird( ns, Promise );
This is a more robust approach.
Combining CLS and promises is a slightly tricky business. There are 3 different conventions one could use (see this issue for more detail).
cls-bluebird
follows the convention of binding .then()
callbacks to the context in which .then()
is called.
1var promise; 2ns.run(function() { 3 ns.set('foo', 123); 4 promise = Promise.resolve(); 5}); 6 7ns.run(function() { 8 ns.set('foo', 456); 9 promise.then(print); 10}); 11 12function print() { 13 console.log(ns.get('foo')); 14} 15 16// this outputs '456' (the value of `foo` at the time `.then()` was called)
Promise.onPossiblyUnhandledRejection()
and Promise.onUnhandledRejectionHandled()
allow you to attach global handlers to intercept unhandled rejections.
The CLS context in which callbacks are called is unknown. It's probably unwise to rely on the CLS context in the callback being that when the rejection occurred - use .catch()
on the end of the promise chain that's created within namespace.run()
instead.
Use npm test
to run the tests. Use npm run cover
to check coverage.
See changelog.md
If you discover a bug, please raise an issue on Github. https://github.com/TimBeyer/cls-bluebird/issues
Pull requests are very welcome. Please:
No vulnerabilities found.
No security vulnerabilities found.