繁体   English   中英

在 sveltekit 上实现挂钩时,我是否必须等待解决 function

[英]Do i have to await the resolve function when implementing hooks on sveltekit

i got this handle implementation for sveltekit hooks and because it returns a promise of response, the resolve function doesn't need to be awaited, since it is a function that either returns a value directly or returns a promise of a value, but this example从文档等待 function。 可以不等待吗?什么时候不等待(如果可以的话)等待

 export const handle:Handle=async ({event,resolve}) => { let sid = getsid(event.request.headers.get('cookie')) event.locals.sessionobj = getSO(sid?sid:'test') return resolve(event) }

不等待也没关系。

等待它的一个原因是,如果您想在响应中添加额外的标头,如第二个示例所示:

export async function handle({ event, resolve }) {
  const response = await resolve(event);
  response.headers.set('x-custom-header', 'potato');
 
  return response;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM