nodejs で promise を使用しようとしています (node-promise パッケージで試しています)。しかし、何の成功もありません。以下のコードを参照してください。
var express = require('express'),
    request = require('request'),
    promise = require('node-promise');
app.get('/promise', function(req, res) {
    var length = -1;
    new promise.Promise(request(
        {uri: "http://www.bing.com"},
        function (error, response, body) {
            if (error && response.statusCode !== 200) {
                console.log("An error occurred when connected to the web site");
                return;
            }
            console.log("I'll return: " + body.length);
            length = body.length;
        }
    )).then(function(result) {
        console.log("This is what I got: " + length);
        console.log("Done!");
    });
    res.end();
});
上記コードの出力I'll return: 35857のみで、その部分には行きませんthen。
次に、コードを次のように変更します。
app.get('/promise', function(req, res) {
    var length = -1;
    promise.when(
        request(
            {uri: "http://www.bing.com"},
            function (error, response, body) {
                if (error && response.statusCode !== 200) {
                    console.log("An error occurred when connected to the web site");
                    return;
                }
                console.log("I'll return: " + body.length);
                length = body.length;
            }
        ),
        function(result) {
            console.log("This is what I got: " + length);
            console.log("Done!");
        },
        function(error) {
            console.log(error);
        }
    );
    res.end();
});
今回の出力はThis is what I got: -1...今回Done!は「約束」が呼び出されなかったようです。
そう:
- 上記のコードを修正するには何が必要ですか? 明らかに私はそれを正しくやっていません:)
 - 私が約束をしているとき、node-promiseは「行くべき道」ですか、それともより良い方法/パッケージがありますか? つまり、よりシンプルで、より本番環境に対応しています。
 
ありがとう。