javascript - Chaining web services calls with promises does not always work -
I'm having trouble, because this does not happen every time: I have webservices with collierges (Dzego / Tastypie ), The promise is only called with sothat WS2 (web service # 2) when WS1 has been executed successfully, etc.
The code looks like this:
myfunc = function () {callPromiseWS1 (). Then (function (data) {callPromiseWS2 ()} .then (function) {callPromiseWS3 ()}}}; WS2 is a post request that writes stuff in database. Which uses the content created by WS2. Sometimes (and not always), WS3 fails because the object that was previously WS2 should have been created by itself. It is not in existence. Of course, if I try the WS3 request manually Manually execute. This works.
I think that WS2 and WS3 are executed in parallel, I do not expect that.
Anyone Thank you. Thank you.
You are missing 3 return statements, but the behavior you are experiencing This is because of a particular:
myfunc = function () {return callPromiseWS1 (). Then (function (data) {return callPromiseWS2 (); // this one}) . Then (function (data) {returns call pymayasevs3 ();})}} If you do not promise that callPromiseWS2 returns, then then () does not know that it is a callPromiseWS2 is complete. Note that if you actually enter the data parameter in each step (or if you right it is callPromiseWS2 and callPromiseWS3 If you are passing as the only parameter), you can simplify this and eliminate the requirement of two return statements and a lot of code above: myfunc = function () {Return callPromiseWS1 () Then (CallPromiseWS2). Then (callPromiseWS3); }; Remember that any work that uses promise, promises back or call .one () . As a matter of personal preference, I think that promises to use a naming scheme for the tasks so that you can return the promises so you know that they make a promise with which Should be dealt with. / div>
Comments
Post a Comment