Skip to content

Instantly share code, notes, and snippets.

@victorquinn
Last active August 29, 2015 13:56

Revisions

  1. victorquinn revised this gist Feb 14, 2014. 2 changed files with 32 additions and 5 deletions.
    34 changes: 30 additions & 4 deletions memoryleak.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    var Promise = require('bluebird'),
    express = require('express'),
    request = require('request'),
    express = require('express');
    step = require('step');

    var app = express();

    @@ -11,7 +12,7 @@ app.post('/test', function(req, res) {

    var server = app.listen(3000);

    function make_request(callback) {
    function make_request_normal(callback) {
    request.post({
    url: "http://localhost:3000/test",
    method: "POST",
    @@ -21,6 +22,25 @@ function make_request(callback) {
    });
    }

    function make_request_with_step(callback) {
    step(
    function() {
    // noop
    this(null, 'test');
    },
    function(err, test) {
    request.post({
    url: "http://localhost:3000/test",
    method: "POST",
    body: JSON.stringify({first_name: "Victor"})
    }, this);
    },
    function(err, response, body) {
    callback(null, response, body);
    }
    );
    }


    // Works fine
    // make_request(function(err, response) {
    @@ -29,8 +49,14 @@ function make_request(callback) {
    // });

    // Blows up?
    Promise.promisify(make_request)().spread(function(response, body) {
    console.log(response);
    // Promise.promisify(make_request_normal)().spread(function(response, body) {
    // console.log(response);
    // console.log(body);
    // server.close();
    // });


    Promise.promisify(make_request_with_step)().spread(function(response, body) {
    console.log(body);
    server.close();
    });
    3 changes: 2 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    "dependencies": {
    "bluebird": "~0.11.5-0",
    "request": "~2.33.0",
    "express": "~3.4.8"
    "express": "~3.4.8",
    "step": "0.0.5"
    }
    }
  2. victorquinn revised this gist Feb 14, 2014. 2 changed files with 39 additions and 4 deletions.
    38 changes: 36 additions & 2 deletions memoryleak.js
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,36 @@
    var Promise = require("bluebird");
    var request = require("request");
    var Promise = require('bluebird'),
    request = require('request'),
    express = require('express');

    var app = express();

    // test endpoint to test this request
    app.post('/test', function(req, res) {
    res.json({success: true});
    });

    var server = app.listen(3000);

    function make_request(callback) {
    request.post({
    url: "http://localhost:3000/test",
    method: "POST",
    body: JSON.stringify({first_name: "Victor"})
    }, function(err, response, body) {
    callback(err, response, body);
    });
    }


    // Works fine
    // make_request(function(err, response) {
    // console.log(body);
    // server.close();
    // });

    // Blows up?
    Promise.promisify(make_request)().spread(function(response, body) {
    console.log(response);
    console.log(body);
    server.close();
    });
    5 changes: 3 additions & 2 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    {
    "dependencies": {
    "bluebird": "~1.0.4",
    "request": "~2.33.0"
    "bluebird": "~0.11.5-0",
    "request": "~2.33.0",
    "express": "~3.4.8"
    }
    }
  3. victorquinn revised this gist Feb 14, 2014. 3 changed files with 8 additions and 1 deletion.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    node_modules
    2 changes: 1 addition & 1 deletion gistfile1.js → memoryleak.js
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    var Promise = require("bluebird");
    var request = require("request");
    var request = require("request");
    6 changes: 6 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    {
    "dependencies": {
    "bluebird": "~1.0.4",
    "request": "~2.33.0"
    }
    }
  4. victorquinn revised this gist Feb 14, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,2 @@
    var Promise = require("bluebird");
    var Promise = require("bluebird");
    var request = require("request");
  5. victorquinn created this gist Feb 14, 2014.
    1 change: 1 addition & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    var Promise = require("bluebird");