Skip to content

Instantly share code, notes, and snippets.

@gaogao-9
Created October 16, 2015 13:44
Show Gist options
  • Save gaogao-9/d23a12316bb6f914926c to your computer and use it in GitHub Desktop.
Save gaogao-9/d23a12316bb6f914926c to your computer and use it in GitHub Desktop.
flyはclearの実装ちょっと丁寧にして欲しいですねぇ…
const fs = require("fs");
//this.clearのあとにこの関数を呼ぶだけ
await this.clear("hoge/fuga");
await checkDelete("hoge/fuga");
async function checkDelete(path){
return new Promise(function check(resolve,reject){
fs.stat(path,(err,stats)=>{
if(!err){
setImmediate(check,resolve,reject);
return;
}
//無事削除されたらresolveする
if(err.errno === -4058){
resolve();
return;
}
reject(err);
});
setTimeout(()=>{
reject("タイムアウトしました")
},1000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment