llrt
llrt copied to clipboard
Is top level await supported?
Hi, is top level await supported?
The following code:
function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
await sleep(100);
export const handle = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
return response.success(200, { message: "hello world!" });
};
with the following config (node20):
esbuild ./src/handler.js --outfile=dist/handler.mjs --platform=node --target=node20 --format=esm --bundle --external:@aws-sdk --external:@smithy --external:uuid
results in cryptic Runtime.ExitError
in logs...
{
"time": "2024-03-01T20:14:59.260Z",
"type": "platform.initRuntimeDone",
"record": {
"initializationType": "on-demand",
"phase": "init",
"status": "error",
"errorType": "Runtime.ExitError"
}
}
Thanks!
Hi there! Not yet, top level is technically possible, but we have to do a significant engine update first so will take some time :) In the meanwhile, you can use a special async init function like so:
function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
export const init = async () => {
// do init here
await sleep(100);
}
export const handle = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
return response.success(200, { message: "hello world!" });
};
Closing as dup of https://github.com/awslabs/llrt/issues/124
duplicating of myself?
duplicating of myself?
Whoops, wrong link! Corrected now 🫡