Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

await work in chrome console without async wrapper [closed]

I've read the MDN definition for await which is : "The await operator is used to wait for a Promise. It can only be used inside an async function."
which works in the editor. However in the chrome console I wrote an async function then in the global execution I typed await functionName and that works perfectly without needing to the async function wrapper, edit: is that supported in the chrome's console just ?

const asyncGreeting = async () => 'Greeting' 

then in the global execution

await asyncGreeting()

the result was "Greeting"

like image 547
Mustafa Alfar Avatar asked Aug 12 '19 11:08

Mustafa Alfar


People also ask

Can you use await without async?

You can use the await keyword on its own (outside of an async function) within a JavaScript module. This means modules, with child modules that use await , wait for the child module to execute before they themselves run, all while not blocking other child modules from loading.

Is await async blocking?

await only blocks the code execution within the async function. It only makes sure that the next line is executed when the promise resolves. So, if an asynchronous activity has already started, await will not have an effect on it.

Does async await support Chrome?

Async functions on Chrome is fully supported on 55-106, partially supported on None of the versions, and not supported on 4-54 Chrome versions. Async functions on Safari is fully supported on 11.1-16, partially supported on None of the versions, and not supported on 3.2-10.1 Safari versions.

Why async await is non blocking?

async lets you use await . That's (almost) all it does (It also wraps your result in a promise). Together they make non-blocking code read like simpler blocking code. They don't unblock code.


1 Answers

Top-level await is a proposed addition to ECMAScript.

Chrome added support for it to the dev tools.

Hence you can see it working in your test.

like image 95
Quentin Avatar answered Oct 20 '22 16:10

Quentin