1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

perf(serve): hoist repeated condition (#19449)

This commit is contained in:
Marvin Hagemeister 2023-06-09 23:21:26 +02:00 committed by GitHub
parent 2b2eebd583
commit ed76456059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -503,16 +503,19 @@ async function asyncResponse(responseBodies, req, status, stream) {
function mapToCallback(context, callback, onError) {
const responseBodies = context.responseBodies;
const signal = context.abortController.signal;
const hasCallback = callback.length > 0;
const hasOneCallback = callback.length === 1;
return async function (req) {
// Get the response from the user-provided callback. If that fails, use onError. If that fails, return a fallback
// 500 error.
let innerRequest;
let response;
try {
if (callback.length > 0) {
if (hasCallback) {
innerRequest = new InnerRequest(req, context);
const request = fromInnerRequest(innerRequest, signal, "immutable");
if (callback.length === 1) {
if (hasOneCallback) {
response = await callback(request);
} else {
response = await callback(request, {