Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Apr 19, 2016
1 parent ea24f3f commit 6d098d5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"

branches:
only:
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cls-bluebird2.js

# Bluebird promises with continuation-local-storage support
# Patch Bluebird promise library to support continuation-local-storage

## Current status

Expand All @@ -12,6 +12,14 @@

## Usage

This very much a work in progress and not ready for use yet.

Patches [bluebird](https://www.npmjs.com/package/bluebird) to work with [continuation-local-storage](https://www.npmjs.com/package/continuation-local-storage).

Only works with bluebird v3.x at present. And not tested, so may not work at all!

Based on original code by [@arthurschreiber](https://github.com/arthurschreiber).

## Tests

Use `npm test` to run the tests. Use `npm run cover` to check coverage.
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Changelog

## Next
## 0.0.1

* Initial release
45 changes: 44 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@
// cls-bluebird2 module
// --------------------

// modules
var Bluebird = require('bluebird/js/release/promise')(),
wrap = require('shimmer').wrap;

// exports
module.exports = function() {
module.exports = function(ns, Promise) {
if (!Promise) Promise = Bluebird;

var async = Promise._async;

function wrapper(original) {
return function(fn, receiver, arg) {
return original.call(this, ns.bind(fn), receiver, arg);
};
}

wrap(async, 'invokeFirst', wrapper);
wrap(async, 'invokeLater', wrapper);
wrap(async, 'invoke', wrapper);

async.settlePromises = function(promise) {
var fn = ns.bind(promise._settlePromises);

if (this._trampolineEnabled) {
this._normalQueue.push(fn, promise, undefined);
this._queueTick();
} else {
this._schedule(function() {
fn.call(promise);
});
}
};

wrap(async, 'throwLater', function(original) {
return function(fn, arg) {
if (arguments.length === 1) {
arg = fn;
fn = function () { throw arg; };
}

return original.call(this, ns.bind(fn), arg);
};
});

return Promise;
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cls-bluebird2",
"version": "0.0.0",
"description": "Bluebird promises with continuation-local-storage support",
"version": "0.0.1",
"description": "Patch Bluebird promise library to support continuation-local-storage",
"main": "./lib/",
"author": {
"name": "Overlook Motel"
Expand All @@ -14,6 +14,8 @@
"url": "https://github.com/overlookmotel/cls-bluebird2/issues"
},
"dependencies": {
"bluebird": "^3.3.5",
"shimmer": "^1.1.0"
},
"devDependencies": {
"mocha": "^2.2.4",
Expand Down

0 comments on commit 6d098d5

Please sign in to comment.