Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Async compilation and instantiation #62

Merged
merged 3 commits into from
Nov 12, 2021
Merged

Async compilation and instantiation #62

merged 3 commits into from
Nov 12, 2021

Conversation

liamappelbe
Copy link
Contributor

Add WasmModule.compileAsync and WasmInstanceBuilder.buildAsync, so that the web API can be supported in the future.

#34

@liamappelbe
Copy link
Contributor Author

@lexaknyazev are there any other functions that need async equivalents?

@lexaknyazev
Copy link

The web platform has these async entry points (all exposed by the wasm_interop package):

  • async compile from bytes or buffer;
  • async instantiate from bytes or buffer;
  • async instantiate from a compiled module.

@liamappelbe
Copy link
Contributor Author

Going directly from bytes to an instance doesn't fit nicely with the way we're doing imports, so I'll leave that out for now.

@liamappelbe liamappelbe marked this pull request as ready for review November 10, 2021 21:16
@@ -21,6 +21,10 @@ class WasmModule {
/// Deserialize a module. See [WasmModule.serialize] for more details.
WasmModule.deserialize(Uint8List data) : this._(data, true);

/// Asynchronously compile a module.
static Future<WasmModule> compileAsync(Uint8List data) async =>
Future<WasmModule>(() => WasmModule(data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Future<WasmModule>(() => WasmModule(data));
WasmModule(data);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor I'm using here defers execution to a later time, but on the same isolate. My idea was that compilation/instantiation might be expensive, so although I can't do the compile on a different isolate, I can at least give the scheduler a chance to prioritize stuff like UI updates. It would be a bit weird to have an async method that can still block for a while.

@liamappelbe liamappelbe merged commit e45e5fb into main Nov 12, 2021
@kevmoo kevmoo deleted the async branch January 21, 2022 22:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants