so if we hit an API on the backend, and it took a while to respond it counts in that execution time?
so if we hit an API on the backend, and it took a while to respond it counts in that execution time?
ctx.waitUntil(handleCountTokens(text));async there.workerd


no support for .ts
npx wrangler pages dev -- SERVER COMMAND . You are also able to get the logs of your functions by pressing "d".export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
... do stuff
ctx.waitUntil(asyncFunction())
return new Response(...)
}async function wait(ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms));
console.log("hello");
}await init((imports) => WebAssembly.instantiate(wasm, imports));
const encoder = new Tiktoken(
model.bpe_ranks,
model.special_tokens,
model.pat_str
);
async function handleCountTokens(data: string) {
return new Promise((resolve, reject) => {
const tokens = encoder.encode(data);
// encoder.free();
resolve({
tokens_count: tokens.length,
});
});
}ctx.waitUntil(handleCountTokens(text));asyncworkerd.tsnpx wrangler pages dev -- SERVER COMMAND