File size: 881 Bytes
bd98362 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 'use strict';
const Router = require('koa-router');
const koabody = require('koa-body')();
const fs = require('fs');
const profiler = require('v8-profiler');
profiler.startProfiling('', true);
console.log('start')
setTimeout(() => {
console.log('stop');
let result = profiler.stopProfiling('');
fs.writeFileSync('./node.cpu.json', JSON.stringify(result));
result.delete();
}, 60 * 1000);
let testTryCatch = (req, res) => {
try {
res.end('tryCatchStatement success!');
} catch (e) {
res.end('tryCatchStatement ' + e.message);
}
}
let testSleep = (req, res) => {
const now = Date.now();
while (Date.now() - now < 200) {}
res.end('testSleep success');
}
let router = new Router();
router.get('/test', koabody, async (ctx, next) => {
testTryCatch(ctx.req, ctx.res);
testSleep(ctx.req, ctx.res);
})
module.exports = router; |