这就是我所拥有的:
async function myFetch() {
let loggerinfo = {
url: await "Hellothere",
token: await "212312"
};
return await loggerinfo;
}
const myfish = myFetch().then((loggerinfo) => {
return loggerinfo
})
console.log(myfish);
我得到了一个";承诺{}"当我输出myfish变量时
我需要async和await属性,但同时,我需要能够使用logginfo变量;myfish";在async和myFetch((.then框之外使用。
例如,我的结果是:
async function myFetch() {
let loggerinfo = {
url: await "Hellothere",
token: await "212312"
};
return await loggerinfo;
}
const myfish = myFetch().then((loggerinfo) => {
return loggerinfo
})
在exports.handler中使用myfish
exports.handler = function (event, context) {
console.log(myfish);
};
async function myFetch() {
let loggerinfo = {
url: await "Hellothere",
token: await "212312"
};
return loggerinfo;
}
const myfish = async () => {return await myFetch();}
使用上面的代码可以获得预期的结果。
在导出中使用myfish。处理程序
exports.handler = async (event, context) {
console.log(await myfish);
}
您可以在lambda函数中使用async/await,也可以如上所述
async function myFetch() {
let loggerinfo = {
url: "Hellothere",
token: "212312"
};
return await loggerinfo;
}
(async () => {
console.log(await myFetch())
})()