-
-
Save gaogao-9/e6675e20b4d67d955946846b1a84bd51 to your computer and use it in GitHub Desktop.
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
//Dummy resource | |
var Resource = { | |
open: function() { | |
var res = { | |
read: function() { | |
return new Promise(function(_resolve, _reject) { | |
setTimeout(function() { | |
_resolve('hogeeee'); | |
//return _reject('read error!'); | |
}, 1000); | |
}); | |
}, | |
close: function() { | |
console.log('Resource is closed.'); | |
} | |
}; | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('Resource is opened.'); | |
return resolve(res); | |
//reject('open error!'); | |
}, 1000); | |
}); | |
} | |
}; |
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
(async ()=> { | |
const res = await Resouce.open("path"); | |
try{ | |
const result = await res.read(); | |
console.log(result); | |
} | |
finally{ | |
res.close(); | |
} | |
})().catch((err)=> console.error((err&&err.stack) || err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment