mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: better executeMiddlewareStack trace
This commit is contained in:
2 files changed
+15
-10
No files matched your search
@@ -287,17 +287,22 @@ class NotFoundHandler extends Handler {
|
||||
all() { }
|
||||
}
|
||||
|
||||
async function executeMiddlewareStack(context: any, middlewares: { name: string, func: Function }[]) {
|
||||
const first = middlewares[0];
|
||||
if (!first) return Promise.resolve();
|
||||
function executeMiddlewareStack(context: any, middlewares: { name: string, func: Function }[]) {
|
||||
let index = -1;
|
||||
context.__timers ||= {};
|
||||
context.__timers[`${first.name}.start`] = Date.now();
|
||||
const next = () => executeMiddlewareStack(context, middlewares.slice(1));
|
||||
try {
|
||||
return await first.func(context, next);
|
||||
} finally {
|
||||
context.__timers[`${first.name}.end`] = Date.now();
|
||||
async function dispatch(i) {
|
||||
if (i <= index) throw new Error('next() called multiple times');
|
||||
index = i;
|
||||
if (!middlewares[i]) return null;
|
||||
const name = middlewares[i].name;
|
||||
context.__timers[`${name}.start`] = Date.now();
|
||||
try {
|
||||
return await middlewares[i].func(context, dispatch.bind(null, i + 1));
|
||||
} finally {
|
||||
context.__timers[`${name}.end`] = Date.now();
|
||||
}
|
||||
}
|
||||
return dispatch(0);
|
||||
}
|
||||
|
||||
interface WebServiceConfig {
|
||||
|
||||
@@ -9,7 +9,7 @@ import Notification from 'vj/components/notification';
|
||||
import { downloadProblemSet } from 'vj/components/zipDownloader';
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
import {
|
||||
addSpeculationRules, delay, i18n, pjax, request, setTemporaryViewTransitionNames, tpl,
|
||||
addSpeculationRules, delay, i18n, pjax, request, tpl,
|
||||
} from 'vj/utils';
|
||||
|
||||
const list = [];
|
||||
|
||||
Reference in new issue
Block a user