I'm trying to figure out a way to resolve/reject a jquery promise in a function that is not directly accessible by the function that creates the promise/deferred.
The scenario is one where a request is sent to another machine and the response to this (which may or may not come) is handled by another function. As soon as I send the request I start a timer which rejects the promise on timeout. To resolve/reject the promise later based on the response from the remote machine, I make this promise accessible to both the send request and recv response (where it is resolved if the resp was a success) functions, however if the code that calls the function to send requests tries to send multiple requests this would not work.
Basically I would like to allow/process only one request at a time until that request is either resolved or rejected even if the calling code tries to send multiple requests. Any ideas on how to achieve this?
Sorry if I sound all over the place, am pretty new to this stuff.
jQuery.ajax(...)or one of its shorthand methods), then all the resolving/rejecting will be managed for you by jQuery. All you need to do is to specify success/error handlers in one or more of a variety of ways and they will fire when the response arrives or the request times out. Post some code and I'm sure someone will be able to advise further. - Beetroot-Beetroot