mongoose中Entity的save操作返回的不是promise吗?
环境: node v8.7.0 mongoose v4.13.9
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
const db = mongoose.createConnection('localhost', 'test')
let userSchema = new mongoose.Schema({
name:String
})
let userModel = db.model('User', userSchema)
let userEntity = new userModel({
name:'a'
})
let save = async function(){
await userEntity.save(()=>{
console.log(1)
})
console.log(2)
}
save()
如果userEntity.save返回值是promise这里应该是先1后2,可是结果是先2后1,这是为什么?
1 回复
https://www.zhihu.com/question/36273908
setTimeout(console.log, 0, 'a')
console.log('b')
console.log('c') bca 同理