module-asyncify.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { QuickJSAsyncContext } from "./context-asyncify";
  2. import { QuickJSAsyncEmscriptenModule } from "./emscripten-types";
  3. import { QuickJSAsyncFFI } from "./variants";
  4. import { ModuleEvalOptions, QuickJSWASMModule } from "./module";
  5. import { QuickJSAsyncRuntime } from "./runtime-asyncify";
  6. import { AsyncRuntimeOptions, ContextOptions } from "./types";
  7. /**
  8. * Asyncified version of [[QuickJSWASMModule]].
  9. *
  10. * Due to limitations of Emscripten's ASYNCIFY process, only a single async
  11. * function call can happen at a time across the entire WebAssembly module.
  12. *
  13. * That means that all runtimes, contexts, functions, etc created inside this
  14. * WebAssembly are limited to a single concurrent async action.
  15. * **Multiple concurrent async actions is an error.**
  16. *
  17. * To allow for multiple concurrent async actions, you must create multiple WebAssembly
  18. * modules.
  19. */
  20. export declare class QuickJSAsyncWASMModule extends QuickJSWASMModule {
  21. /** @private */
  22. protected ffi: QuickJSAsyncFFI;
  23. /** @private */
  24. protected module: QuickJSAsyncEmscriptenModule;
  25. /** @private */
  26. constructor(module: QuickJSAsyncEmscriptenModule, ffi: QuickJSAsyncFFI);
  27. /**
  28. * Create a new async runtime inside this WebAssembly module. All runtimes inside a
  29. * module are limited to a single async call at a time. For multiple
  30. * concurrent async actions, create multiple WebAssembly modules.
  31. */
  32. newRuntime(options?: AsyncRuntimeOptions): QuickJSAsyncRuntime;
  33. /**
  34. * A simplified API to create a new [[QuickJSRuntime]] and a
  35. * [[QuickJSContext]] inside that runtime at the same time. The runtime will
  36. * be disposed when the context is disposed.
  37. */
  38. newContext(options?: ContextOptions): QuickJSAsyncContext;
  39. /** Synchronous evalCode is not supported. */
  40. evalCode(): never;
  41. /**
  42. * One-off evaluate code without needing to create a [[QuickJSRuntimeAsync]] or
  43. * [[QuickJSContextSync]] explicitly.
  44. *
  45. * This version allows for asynchronous Ecmascript module loading.
  46. *
  47. * Note that only a single async action can occur at a time inside the entire WebAssembly module.
  48. * **Multiple concurrent async actions is an error.**
  49. *
  50. * See the documentation for [[QuickJSWASMModule.evalCode]] for more details.
  51. */
  52. evalCodeAsync(code: string, options: ModuleEvalOptions): Promise<unknown>;
  53. }