This function works as expected: ```async function wait(ms: number) { await new Promise((resolve)

This function works as expected:
async function wait(ms: number) {
  await new Promise((resolve) => setTimeout(resolve, ms));
  console.log("hello");
}

and this waits until completion before returning:
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,
    });
  });
}
Was this page helpful?