mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
perf(serve): hoist promise error callback (#19456)
This commit is contained in:
parent
a0a7a65cc3
commit
855772b663
1 changed files with 11 additions and 16 deletions
|
@ -680,6 +680,15 @@ function serveHttpOn(context, callback) {
|
||||||
let currentPromise = null;
|
let currentPromise = null;
|
||||||
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
|
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
|
||||||
|
|
||||||
|
const promiseErrorHandler = (error) => {
|
||||||
|
// Abnormal exit
|
||||||
|
console.error(
|
||||||
|
"Terminating Deno.serve loop due to unexpected error",
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
context.close();
|
||||||
|
};
|
||||||
|
|
||||||
// Run the server
|
// Run the server
|
||||||
const finished = (async () => {
|
const finished = (async () => {
|
||||||
const rid = context.serverRid;
|
const rid = context.serverRid;
|
||||||
|
@ -689,14 +698,7 @@ function serveHttpOn(context, callback) {
|
||||||
// Attempt to pull as many requests out of the queue as possible before awaiting. This API is
|
// Attempt to pull as many requests out of the queue as possible before awaiting. This API is
|
||||||
// a synchronous, non-blocking API that returns u32::MAX if anything goes wrong.
|
// a synchronous, non-blocking API that returns u32::MAX if anything goes wrong.
|
||||||
while ((req = op_http_try_wait(rid)) !== 0xffffffff) {
|
while ((req = op_http_try_wait(rid)) !== 0xffffffff) {
|
||||||
PromisePrototypeCatch(callback(req), (error) => {
|
PromisePrototypeCatch(callback(req), promiseErrorHandler);
|
||||||
// Abnormal exit
|
|
||||||
console.error(
|
|
||||||
"Terminating Deno.serve loop due to unexpected error",
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
context.close();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
currentPromise = op_http_wait(rid);
|
currentPromise = op_http_wait(rid);
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
|
@ -713,14 +715,7 @@ function serveHttpOn(context, callback) {
|
||||||
if (req === 0xffffffff) {
|
if (req === 0xffffffff) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PromisePrototypeCatch(callback(req), (error) => {
|
PromisePrototypeCatch(callback(req), promiseErrorHandler);
|
||||||
// Abnormal exit
|
|
||||||
console.error(
|
|
||||||
"Terminating Deno.serve loop due to unexpected error",
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
context.close();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const streamRid of new SafeSetIterator(context.responseBodies)) {
|
for (const streamRid of new SafeSetIterator(context.responseBodies)) {
|
||||||
|
|
Loading…
Reference in a new issue