Created
April 16, 2016 13:01
-
-
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
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
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