Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If everything works fine with <code>xhr.open('POST', url, false)</code>, then is would appear the sever doesn't handle multiple simultaneous requests properly. With async off, the requests are effectively forced to be handled sequentially.</p> <p>The ideal solution would probably be to fix things at the server, however is <strong>may</strong> be acceptable to apply a better client-side "sequentializer" fix.</p> <p>The code follows a fairly familiar pattern :</p> <pre><code>var promise = Q.defer().resolve().promise;//A ready-resolved seed promise. //Now, instead of pushing promises onto an array, progressively build a .then() chain. for (var i = txArray.length - 1; i &gt;= 0; i--) { txArray[i]._action = 'update'; promise = promise.then(function() { return newVertex(url); }); }; //And add a terminal .then() to do whatever on completion of the sequence. promise.then(function(result) { console.log(result); }); </code></pre> <p>This allows <code>xhr.open('POST', url, true);</code> to be used in <code>newVertex()</code> (ie asynchronous requests).</p> <p>I'm not too sure about the last <code>.then()</code>. You may need to play with it some.</p> <h2>Footnote</h2> <p>This fix ensures that each user's requests are sequential. However, the bug at the server will remain. Only by fixing whatever is wrong at the server will you ensure that concurrent requests from two or more users do not give the problem; namely that duplicate ids can be issued. This will not necessarily occur during testing and could be a latent bug that does not manifest itself until some time in the future, when two users access this particular resource concurrently. </p> <p>Therefore, the above fix is only appropriate if only <strong>one</strong> user can access the resource (and potentially, similar resources) concurrently. To be safe, you would need to take measures at the server to ensure that multiple concurrent access to the resource(s) cannot occur. It is almost undoubtedly easier to fix the actual bug - ie to ensure that the same id cannot be issued more than once. </p> <p>I therefore reiterate that the above solution only <strong>may</strong> be acceptable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload