Skip to content

Promise Chains #3251

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

Closed
ghost opened this issue Dec 17, 2016 · 2 comments
Closed

Promise Chains #3251

ghost opened this issue Dec 17, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 17, 2016

Quick question, has Parse.Promise.when chaining changed from parse.com to parse-server? I don't seem to be returning the correct item.

return Parse.Promise.when([
    Parse.Cloud.httpRequest({
        url:'https://graph.facebook.com/v2.1/me?fields=picture.height(50).width(50),email,first_name,last_name,friends.limit(5000),name,gender&access_token='+access_token
    }), Parse.Cloud.httpRequest({
        url:'https://graph.facebook.com/v2.1/me?fields=picture.height(500).width(500)&access_token='+access_token
    })]).then(function (facebookResponse, facebookImage) {

        // Append larger image to response
        try {
            facebookResponse.data.pictureLarge = {};
            facebookResponse.data.pictureLarge.data = {};
            facebookResponse.data.pictureLarge.data.url = facebookImage.data.picture.data.url;
        } catch(e) {}

        return facebookResponse;

    }, function (error) {

        // Can catch it and return a success
        return Parse.Promise.as(false);

    }).then(function (facebookResponse) {

        // Success
        return facebookResponse;

    });

On parse.com, it would return facebookResponse, and on parse-server, I'm getting [facebookResponse, facebookImage] instead of facebookResponse.

Any ideas?

@ghost
Copy link
Author

ghost commented Dec 19, 2016

Update: I solved the issue by removing the array brackets as the input to the Parse.Promise.when function.

@ghost
Copy link
Author

ghost commented Dec 20, 2016

Just a follow up, I always assumed that the first and only input into a parallel promise chain was an array of promises, much like q:

// Q ALL PROMISE

var firstPromise = function () {

    // Setup Promise
    var deferred = q.defer();

    if (!blah)
        deferred.resolve();

    var first_parallel = function () {

        // Promise is resolved
        deferred.resolve();

    };

    first_parallel();

    return deferred.promise;
};

var secondPromise = function () {

    // Setup Promise
    var deferred = q.defer();

    if (!blah)
        deferred.resolve();

    var second_parallel = function () {

        // Promise is resolved
        deferred.resolve();

    };

    second_parallel();

    return deferred.promise;
};

q.all(promises).then(function () {
   // Promise done
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant