我想编写一个类似于以下内容的模块。
应该可以通过“ Server.doBackup”调用它,并使用 fat箭头符号和 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
答案 0 :(得分:3)
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))