[英]How to write async function a module function using fat arrow notation
我想写一个类似于下面的模块 。
应该可以通过“ Server.doBackup”来调用它,并使用胖箭头符号和async-await函数
有任何想法吗? 您可以在下面提供我的代码段的更正版本吗?
const Server = {
config: {
documents: ['DEFAULT', 'KEYS'],
exportpath: 'data/exportFromCosmos/',
uploadpath: 'data/uploadToAzureBlob/',
crosscheckFile: 'data/crosscheckFile.txt'
},
doBackup: () => async {
let prepareFolders = await Folders.prepare(Server.config, resolve)
let downloadDB_DEFAULT = await Database.downloadDocumentsOfType_DEFAULT()
let downloadDB_KEYS = await Database.downloadDocumentsOfType_KEYS()
let zipDocuments = await Documents.zip(Server.config)
}
}
module.exports = Server
const Server = { config: { documents: ['DEFAULT', 'KEYS'], exportpath: 'data/exportFromCosmos/', uploadpath: 'data/uploadToAzureBlob/', crosscheckFile: 'data/crosscheckFile.txt' }, doBackup: async () => { let prepareFolders = await Folders.prepare(Server.config, resolve) let downloadDB_DEFAULT = await Database.downloadDocumentsOfType_DEFAULT() let downloadDB_KEYS = await Database.downloadDocumentsOfType_KEYS() let zipDocuments = await Documents.zip(Server.config) } } module.exports = Server
//示例代码
async function findName(){ return {name: "Stack"} } let user = { getName: async()=>{ let {name} = await findName() return name } } user.getName() .then((userDetail)=> console.log(userDetail)) .catch((error) => console.log(error))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.