![](/img/trans.png)
[英]Why do I have to return Unit.INSTANCE when implementing in Java a Kotlin function that returns a Unit?
[英]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.