Description
Is your feature request related to a problem? Please describe.
It should be pretty common for a svelt kit app to utilize external services that you need to initialize clients to talk to them. The doc demonstrates such use case:
import db from '$lib/database';
export async function get({ params }) {
const { slug } = params;
const article = await db.get(slug);
// ...
}
One issue with this code is that it assumes db
can be initialized in the module itself either synchronously (which is not always the case) or via top-level await
(which svelte kit doesn't seem to support).
Describe the solution you'd like
Offer a hook like async func init() {}
that only runs once when it starts?
Describe alternatives you've considered
How important is this feature to you?
Very, since it's pretty awkward to workaround when the initialization is async (e.g., force initialization to be synchronous and only call the async part when actually talk to external services).
Additional context