Skip to content

Instantly share code, notes, and snippets.

@koonuf
Created June 3, 2018 20:33
Show Gist options
  • Save koonuf/65242487f7534d96c2b7423fc7115f07 to your computer and use it in GitHub Desktop.
Save koonuf/65242487f7534d96c2b7423fc7115f07 to your computer and use it in GitHub Desktop.
function removeDirWithRetries(folderPath) {
let delay = 50;
let attempts = 5;
const retryFunc = () => fsa.rmdirAsync(folderPath).catch((e) => {
if (e.code === "ENOTEMPTY") {
attempts--;
if (attempts > 0) {
return Promise.delay(delay *= 2).then(retryFunc);
}
}
throw e;
});
return retryFunc();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment