Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssemblyScript Loader #200

Closed
marcus-sa opened this issue Aug 2, 2018 · 6 comments
Closed

AssemblyScript Loader #200

marcus-sa opened this issue Aug 2, 2018 · 6 comments
Labels

Comments

@marcus-sa
Copy link

marcus-sa commented Aug 2, 2018

I've been trying this project out for a few days, and I must say, usage wise I'm pretty confused.
First of all there's no NPM package for https://github.com/AssemblyScript/assemblyscript/tree/master/lib/loader available as shown in the docs that there should be.

export declare function instantiateStreaming<T extends {}>(response: Response, imports?: ImportsObject): Promise<ASUtil & T>;

Should be Promise<Response> and not Response.


Should be optional.

We need some examples, because I'm really confused on how some things should be done.
E.g using module.getString and module.newString, because when I try to log something from my AssemblyScript file all it logs is a number which makes sense.
But what are the purpose of these two functions?
The docs definitely needs to be updated.

dcodeIO added a commit that referenced this issue Aug 2, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Aug 2, 2018

Thanks, I updated the declaration to Promise<Response>. Regarding documentation, there is an example here. Doesn't that explain the usage sufficiently?

Essentially, newString allocates a new string in WASM memory returning a pointer to it, while getString reads such a segment to a JS string when provided with its pointer.

@marcus-sa
Copy link
Author

marcus-sa commented Aug 3, 2018

Surely it does, but you'd have to wait for the initialized stream to complete before the module is available, otherwise it'll throw undefined. So I'd have to end up wrapping the stream in a callback like this and wait for it to finish before defining the imports.
https://github.com/marcus-sa/assemblyscript-starter/blob/master/public/main.ts

@dcodeIO
Copy link
Member

dcodeIO commented Aug 3, 2018

Well, you could also use await to simplify this

// (async function() {
  var myModule = await ASLoader.instantiateStreaming(...);
  ...
// })();
...

or make use of the Promise as usual:

ASLoader.instantiateStreaming(...).then(myModule => {
  ...
});

@marcus-sa
Copy link
Author

Already tried that, sadly it doesn't work.

@MaxGraey
Copy link
Member

MaxGraey commented Aug 4, 2018

In node.js instantiateStreaming not working yet. But it should on latest Firefox, Chrome, Safari and Edge

@dcodeIO
Copy link
Member

dcodeIO commented Feb 7, 2019

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!

@dcodeIO dcodeIO closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants