Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises #753

Closed
3goats opened this issue Feb 11, 2015 · 5 comments
Closed

Promises #753

3goats opened this issue Feb 11, 2015 · 5 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@3goats
Copy link

3goats commented Feb 11, 2015

Hi,

I've been using Bluebird in some of my other ECMA5 projects to provide support for promises. I'm looking to build a new project using ECMA6 and will need support for Promises. Since the whole ECMA6 and 6to5 thing is still so new, I'm struggling to understand the best way to add this to my project.

Do I just use Bluebird as per my ECMA5 code or is there a good way to do this using 6to5 ?

This is an example of my working my ECMA5 code:

var Promise = require("bluebird");
var Request = Promise.promisify(require('request'));

function callhttp(host) {

    var cert = " ";

    var options = {
        url: 'https://' + host,
        method: "GET",
        headers: {
            'User-Agent': 'request'
        }
    };

    return Request(options).spread(function (response, body) {
        if (response.statusCode == 200) {
           // console.log(body)
            console.log(response.connection.getPeerCertificate().subject.CN)
            return {
                CN: response.connection.getPeerCertificate().subject.CN,
            };
        } else {
            // Just an example, 200 is not the only successful code
            throw new Error("HTTP Error: " + response.statusCode);
        }
    });
}


var join = Promise.join;
join(
    callhttp("www.google.com"),
    callhttp("www.microsoft.com"),
    callhttp("www.adobe.com"),
    function (first, second, third) {
        console.log([first, second, third]);
    });
@sebmck
Copy link
Contributor

sebmck commented Feb 11, 2015

If you're using bluebird then there's no real reason to stop. It provides a superset of the features and methods available in ES6 Promises so you're likely going to be relying on some of those already.

@stefanpenner
Copy link
Member

It provides a superset of the features

/pedantic statement

actually it is an improper superset, more like c <-> c++. As it diverges in some scenarios, including subclassing. But don't let me scare you from it, bluebird is a rock solid promise implementation.

/#pedantic statement

@sebmck
Copy link
Contributor

sebmck commented Feb 11, 2015

@stefanpenner Ah great, thanks for the clarification. I'm not familiar with the Promise ecosystem as much as I'd like.

@stefanpenner
Copy link
Member

If people don't utilize the a good proportion of the feature set, it may be slightly byte size heavy. But the 2-4 extra TCP packets it costs I doubt hurt anyone. In most cases, the cost of thinking saving those bytes is higher.

@3goats
Copy link
Author

3goats commented Feb 11, 2015

Thanks for the input here guys. Very helpful.

@3goats 3goats closed this as completed Feb 11, 2015
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants