为什么云函数入口执行不了setTimeout
发布于 5 年前 作者 pwu 15550 次浏览 来自 问答

// 云函数入口函数

exports.main = async (event, context) => {

console.log(‘Start—>A’);

setTimeout(function () {

console.log(‘Time out’);

}, 100);

console.log(‘Start—>End’);

}

2 回复

谢谢你,大神~~~

写法有误 setTimeout是异步的

你需要改成同步的。  Promise

await  new Promise(function (resolve, reject) {

    setTimeout(function () {

      console.log("Time out")

      resolve({

        data: "很好" 

      })

    }, 100)

回到顶部