gpt4 book ai didi

javascript - 如何使用粗箭头表示法编写异步函数模块函数

转载 作者:行者123 更新时间:2023-11-30 08:21:41 24 4
gpt4 key购买 nike

我想编写一个类似于下面的模块

它应该可以通过“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))

关于javascript - 如何使用粗箭头表示法编写异步函数模块函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52549266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com