Skip to content

Instantly share code, notes, and snippets.

@badursun
Forked from ogostos/four.js
Last active March 25, 2023 19:10
Show Gist options
  • Save badursun/6f5a66aa6e6d3259a9c0eae597c53166 to your computer and use it in GitHub Desktop.
Save badursun/6f5a66aa6e6d3259a9c0eae597c53166 to your computer and use it in GitHub Desktop.
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