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

Requests Sharing deferred object #9

Open
mbowen000 opened this issue Sep 22, 2015 · 1 comment
Open

Requests Sharing deferred object #9

mbowen000 opened this issue Sep 22, 2015 · 1 comment

Comments

@mbowen000
Copy link

I've noticed that sometimes when I am performing some action when a promise comes back from some kind of request - it is possible that the request will hand back a promise that does not belong to the current request (the one I expect will be evaluated). For example:

return force.query('SELECT Id, FROM PricebookEntry').then(function(response) {
    pricebookentries = response.records;
});

return force.query('SELECT Id, FROM Account').then(function(response) {
    accounts = response.records;
});

If I perform these two queries in parallel - I have seen times where the response callback for the Account query will return the results from the PricebookEntry query. It's like the wires are getting crossed. I got around the problem by doing each successive call in a .then() block but that doesn't seem ideal.

Looking at the forceng source - I see this in the code:

 function request(obj) {

            if (!oauth || (!oauth.access_token && !oauth.refresh_token)) {
                deferred.reject('No access token. Login and try again.');
                return;
            }

            var method = obj.method || 'GET',
                headers = {},
                url = getRequestBaseURL();
            deferred = $q.defer();

Notice that the deferred is defined as a window variable (not var). So the deferred is actually shared across requests, which is interesting - and looks to be by design. Can you explain if this is the case and it is indeed supposed to operate like that? And if so, how to best perform multiple asynchronous requests without worrying about getting information for another request during promise resolve?

Thanks!

@mbowen000
Copy link
Author

Just looked at the closed issues and found this:
#7

My question now is - why is it closed but the merge was never done? I'll make the fix on my local branch but was just wondering..

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