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:
parent
2b2eebd583
commit
ed76456059
1 changed files with 5 additions and 2 deletions
|
@ -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, {
|
||||
|
|
Loading…
Reference in a new issue