-
Notifications
You must be signed in to change notification settings - Fork 5
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
Why does this use top-level await
?
#30
Comments
The reading and writing functions have to be async because the Compression Streams API only provides async compression and decompression endpoints, so you can't synchronously compress and decompress files, unfortunately. |
Well I don't need compression. I just need to be able to merge SNBT strings (like I could just remove the compression and decompression part from the library manually. But that means I won't be able to update the library. So I don't really know what to do. |
Oh alright then, that works without await luckily. |
Well I thought of that but it seems I cant just do |
Where are you importing these, in Node, or in the browser? Sounds like it might be the <script type="module">
import { parse, stringify } from "https://cdn.jsdelivr.net/npm/nbtify/dist/index.min.js";
</script> Or if your project isn't set up to use <script>
import("https://cdn.jsdelivr.net/npm/nbtify/dist/index.min.js").then(NBT => {
const { parse, stringify } = NBT;
console.log(parse,stringify);
});
</script> I'd personally rather wrap all of my application logic in an <script>
(async () => {
const { parse, stringify } = await import("https://cdn.jsdelivr.net/npm/nbtify/dist/index.min.js");
console.log(parse,stringify);
})();
</script> The reason the first example works without any uses of |
It appears that the I'm not gonna question it. I will reopen this issue if I encounter another problem. |
Update: Apparently, running the site from |
Interesting. Are you using Vite to build your site? |
If you have a link to your code or an example of how it's set up, I can try and help debug it with you. |
Actually, I think the question I should be asking is not "Why does this use const NODE_DEFLATE_RAW_POLYFILL: boolean = await (async () => {
try {
new CompressionStream("deflate-raw");
new DecompressionStream("deflate-raw");
return false;
} catch {
try {
await import("node:zlib");
return true;
} catch {
return false;
}
}
})(); I don't think this is necessary, is it? |
Aah ok, yeah I can find a way to refactor that part. It should probably work instead just from inside an |
Commit bb1f6cb fixed the issue! Thanks! |
Great! Thanks again for the feedback here. I'm currently working on publishing this and some other features to a new version on npm. |
await
?await
?
It seems unnecessary...
And my framework doesn't seem to support top-level await.
The text was updated successfully, but these errors were encountered: