docs: apply Date.now() to all docs (#988)

This commit is contained in:
Equim 2017-05-21 23:33:25 +08:00 committed by Yiyu He
parent 302814e7a3
commit 08eb1a20c3
4 changed files with 12 additions and 12 deletions

View file

@ -70,9 +70,9 @@ app.use(async (ctx, next) => {
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
app.use((ctx, next) => {
const start = new Date();
const start = Date.now();
return next().then(() => {
const ms = new Date() - start;
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
});

View file

@ -81,18 +81,18 @@ const app = new Koa();
// x-response-time
app.use(async function (ctx, next) {
const start = new Date();
const start = Date.now();
await next();
const ms = new Date() - start;
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
// logger
app.use(async function (ctx, next) {
const start = new Date();
const start = Date.now();
await next();
const ms = new Date() - start;
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
});

View file

@ -13,9 +13,9 @@
```js
async function responseTime(ctx, next) {
const start = new Date();
const start = Date.now();
await next();
const ms = new Date() - start;
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
}

View file

@ -39,9 +39,9 @@ It is however recommended that you choose to migrate all v1.x middleware as soon
```js
// Koa will convert
app.use(function *(next) {
const start = new Date();
const start = Date.now();
yield next;
const ms = new Date() - start;
const ms = Date.now() - start;
console.log(`${this.method} ${this.url} - ${ms}ms`);
});
```
@ -52,9 +52,9 @@ You could do it manually as well, in which case Koa will not convert.
const convert = require('koa-convert');
app.use(convert(function *(next) {
const start = new Date();
const start = Date.now();
yield next;
const ms = new Date() - start;
const ms = Date.now() - start;
console.log(`${this.method} ${this.url} - ${ms}ms`);
}));
```