Update crypto.subtle.digest() example in to fix async/await usage problems #1443
Closed
1 of 3 tasks
Labels
Content:WebAPI
Web API docs
help wanted
If you know something about this topic, we would love your help!
@bbrown-spsu commented on Wed Dec 09 2020
Request type
Details
The examples on this page will not run in Firefox 83.0 64 bit. That appears to be because "await" is not within an async function on the next-to-last line. The message I get is "Uncaught SyntaxError: await is only valid in async functions and async generators"
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
@MendyBerger commented on Sun Dec 20 2020
As pointed out by @bbrown-spsu this is because of an
await
that is not in anasync
function.What is the general rule when it come's to cases like this? Do we wrap it with an
async
iife (would probably bloat the code samples)? Do we assume that users will understand that they have to put it in anasync
function? Any other options?Worth pointing out that this is not an example that is meant to be run from withing the page like
interactive-examples
, but rather its a code sample.@bbrown-spsu commented on Sun Dec 20 2020
A couple of thoughts...
I think the very minimum change would be a comment before the call:
// The code below must itself be within an async function.
Better would be a real async function (not iife) called by a non-async function, in other words, something that could be clipped out and run. It would double the length of the example, but more than double the usefulness of the example.@chrisdavidmills commented on Mon Dec 21 2020
I would be happy for you to fix them up so they are runnable at a basic level. I agree with @bbrown-spsu here, and async/await is still fairly new.
The text was updated successfully, but these errors were encountered: