-
-
Notifications
You must be signed in to change notification settings - Fork 673
Align loader API with WebAssembly API #916
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
Conversation
Could we also use |
I think so, if there is a proper check to determine that |
you mean something like function isPromiseLike(p: any): p is PromiseLike {
return !!p && p.then instanceof Function;
} |
The question I had in mind was "what if the argument is not directly a response, but a promise for a response - how can we differentiate that from a promise for something else?" |
You mean how detect is object is Promise (promise like) and this Promise contain Response object without resolving Promise? I guess it hard to detect. Better try resolve this promise and check |
Would then look like async function instantiate(moduleOrBuffer, imports) {
if (
typeof Response !== "undefined" && (
typeof moduleOrBuffer.then === "function" ||
moduleOrBuffer instanceof Response
)
) return instantiateStreaming(moduleOrBuffer, imports);
return postInstantiate(
preInstantiate(imports || (imports = {})),
(await WebAssembly.instantiate(moduleOrBuffer, imports)).instance
);
} Hmm... |
LGTM |
This makes
loader.instantiate
asynchronous to align withWebAssembly.instantiate
and replacesloader.instantiateBuffer
withloader.instantiateSync
accepting both a pre-compiled module or a buffer, just likeloader.instantiate
.