用猫鼬模式获取器异步等待

时间:2020-06-24 19:05:02

标签: node.js mongoose

我正在尝试用猫鼬模式实现异步等待,这是示例代码

const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const UserSchema = mongoose.Schema(
  {
    name: {
      type: String,
      get: async (v) => {
        await delay(1000);  // will be my Http request to modify the value
        return "Hello Async";
      },
    }
    });

getter没有返回{}的{​​{1}}实例

0 个答案:

没有答案