Last active
July 21, 2017 10:01
-
-
Save develar/9405c4430fac7e556aaa94cdf3b49a9d to your computer and use it in GitHub Desktop.
WEB-27555 — without await
This file contains hidden or 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
'use strict'; | |
const path = require('path'); | |
const fs = require('fs'); | |
const promisify = require('util').promisify; | |
const unlink = promisify(fs.unlink); | |
const rmDir = promisify(fs.rmdir); | |
const readDir = promisify(fs.readdir); | |
const lstat = promisify(fs.lstat); | |
const deleteFile = async (dir, file) => { | |
const filePath = path.join(dir, file); | |
try { | |
return deleteDirectory(filePath); | |
} | |
catch (e) { | |
console.error("Handle error") | |
} | |
}; | |
const deleteDirectory = async dir => { | |
let files = await readDir(dir); | |
await Promise.all( | |
files.map(file => deleteFile(dir, file)) | |
); | |
await rmDir(dir); | |
}; | |
deleteFile("sdfsdf", "wefwe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment