-
-
Save badursun/6f5a66aa6e6d3259a9c0eae597c53166 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dequeue() { | |
if (this.workingOnPromise) { | |
return false; | |
} | |
const item = this.queue.shift(); | |
if (!item) { | |
return false; | |
} | |
try { | |
this.workingOnPromise = true; | |
item.promise() | |
.then((value) => { | |
this.workingOnPromise = false; | |
item.resolve(value); | |
this.dequeue(); | |
}) | |
.catch(err => { | |
this.workingOnPromise = false; | |
item.reject(err); | |
this.dequeue(); | |
}) | |
} catch (err) { | |
this.workingOnPromise = false; | |
item.reject(err); | |
this.dequeue(); | |
} | |
return true; | |
} | |
Queue.enqueue(()=>{ | |
console.log('QUEUED: Promise'); | |
return $.ajax("post", "url", [{}]) | |
.then(function(res){ | |
}) | |
.finally(()=>{ | |
console.log('Push Coordinate Resolved'); | |
}) | |
.catch(function (err) { | |
console.log('ERROR: Promise return error: ', err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment