Koa 使用延迟函数


Koa 使用延迟函数 只需要在代码中加入 Promise 即可

router.post('/save', async (ctx, next) => {
  var data = ctx.request.body;
async function delay(time) {
    return new Promise(function (resolve, reject) {
      setTimeout(function () {
        resolve();
      }, time);
    });
  };
  await delay(300);
  ctx.body = {
    code: 200
  }

koa