Issue
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 from the docs awaits the function. is it ok not to await and when to and not to (if it's ok) await
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)
}
Solution
It is ok to not await it.
A reason to await it would be if you want to add extra headers to the response as in the second example:
export async function handle({ event, resolve }) {
const response = await resolve(event);
response.headers.set('x-custom-header', 'potato');
return response;
}
Answered By - Stephane Vanraes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.