Last active
March 22, 2018 12:09
-
-
Save omariosouto/ffbc5172fc093054ed365176d796b477 to your computer and use it in GitHub Desktop.
Async, Recursive .... function!
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
async function awaitSubmissionFinish(submissionID) { | |
const response = await submissionInfo(submissionID) | |
if(submissionHasFinished(response.status)) return response | |
return new Promise(resolve => { | |
setTimeout(() => resolve(awaitSubmissionFinish(submissionID)), 5000) | |
}) | |
} | |
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
async function awaitSubmissionFinish(submissionID, status) { | |
const response = await submissionInfo(submissionID) | |
if(status == 0) { | |
console.log('Submissão terminou') | |
return response | |
} else { | |
console.log('Submissão não terminou') | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve(awaitSubmissionFinish(submissionID, response.status)) | |
}, 5000) | |
}) | |
} | |
} |
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
async function awaitSubmissionFinish(submissionID) { | |
const response = await submissionInfo(submissionID) | |
if(submissionHasFinished(response.status)) return response | |
return new Promise(resolve => { | |
setTimeout(() => resolve(awaitSubmissionFinish(submissionID)), 5000) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment