云环境中setTimeout调用为什么没有在指定时间执行?
在某个云函数,写了如下代码:
console.log("timer start")setTimeout(function () { console.log("timer end") const tdb = cloud.database() tdb.collection('test').add({ data: { time: db.serverDate() } }).then(res => { if (res.errMsg.indexOf('ok') == -1) { console.log(res) console.log("add test failed.") return null } })}, 10000) |
期望10秒后执行添加记录到test数据库的操作,但是10秒后代码并没有执行。
等到20秒后某个来自小程序端的请求来了,此时添加test记录的那段代码就执行了。
这是什么原因呢?
