Skip to content

Instantly share code, notes, and snippets.

@witnessmenow
Created April 16, 2016 13:01
Show Gist options
  • Save witnessmenow/91b994ee70a504a6b48e8c2b09790018 to your computer and use it in GitHub Desktop.
Save witnessmenow/91b994ee70a504a6b48e8c2b09790018 to your computer and use it in GitHub Desktop.
A queue of promises that for the given url will wait for 3 seconds and then upload it to gfycat
var uploadQueue
var addGifToUploadQueueWithDelay = (url) => {
var delayAndUpload = () => {
return delay().then(uploadGifToGfycat.bind(null, url));
}
//Queue is either empty or finished
if(!uploadQueue || uploadQueue.isFulfilled()){
uploadQueue = delayAndUpload();
}
else {
uploadQueue = uploadQueue.then(delayAndUpload);
}
return uploadQueue;
}
var DELAY = 3000;
var delay = () => new Promise ((resolve) =>
{
setTimeout(resolve, DELAY);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment