Commit 39410331 authored by analog-nico's avatar analog-nico
Browse files

Added experimental support for continuation local storage (see issue #64)

parent d3467526
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -156,4 +156,9 @@ request.Request.prototype.pipe = RP$noStreaming;
request.Request.prototype.pipeDest = RP$noStreaming;
request.Request.prototype.pipeDest = RP$noStreaming;




request.bindCLS = function RP$bindCLS(ns) {
    require('cls-bluebird')(ns);
};


module.exports = request;
module.exports = request;
+2 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
  },
  },
  "dependencies": {
  "dependencies": {
    "bluebird": "^2.3",
    "bluebird": "^2.3",
    "cls-bluebird": "^1.0.1",
    "lodash": "^3.10.0",
    "lodash": "^3.10.0",
    "request": "^2.34"
    "request": "^2.34"
  },
  },
@@ -38,6 +39,7 @@
    "chai": "2.2.x",
    "chai": "2.2.x",
    "chai-as-promised": "4.3.x",
    "chai-as-promised": "4.3.x",
    "chalk": "^1.1.1",
    "chalk": "^1.1.1",
    "continuation-local-storage": "^3.1.4",
    "event-stream": "3.3.x",
    "event-stream": "3.3.x",
    "gulp": "3.8.x",
    "gulp": "3.8.x",
    "gulp-coveralls": "0.1.x",
    "gulp-coveralls": "0.1.x",
+34 −0
Original line number Original line Diff line number Diff line
'use strict';

var rp = require('../../../lib/rp.js');
var cls = require('continuation-local-storage');


var ns = cls.createNamespace('testNS');
rp.bindCLS(ns);


function print() {
    ns.run(function () {

        ns.set('value', ns.get('value') + 1);

        console.log(ns.get('value'));

    });
}

ns.run(function () {

    ns.set('value', 0);

    rp('http://localhost:4000/200')
        .then(function () {
            ns.run(function () {
                ns.set('value', ns.get('value') + 1);

                setTimeout(print);
            });
        });

});
+17 −0
Original line number Original line Diff line number Diff line
@@ -1040,6 +1040,23 @@ describe('Request-Promise', function () {


    });
    });


    describe('should support continuation local storage', function () {

        it('with an untouched Bluebird prototype bound to a single namespace', function (done) {

            childProcess.exec('node ' + path.join(__dirname, '../fixtures/cls/single-namespace.js'), function (err, stdout, stderr) {
                try {
                    expect(stdout).to.contain('2\n');
                    done();
                } catch (e) {
                    done(e);
                }
            });

        });

    });

    describe('should run the examples', function () {
    describe('should run the examples', function () {


        it('in the README', function () {
        it('in the README', function () {