Can You Await a Non Async Function?

Can You Await a Non Async Function?

Top level await
You can use the await keyword on its own (outside of an async function) within a JavaScript module.

Can you call an async function from a non async function?

Just treat async call as promise and attach . ... then to it: async function wait() { await new Promise(resolve => setTimeout(resolve, 1000)); return 10; } function f() { // shows 10 after 1 second wait().

Can you await a non async function C#?

Using async void methods

Every now and then you'll find yourself in a synchronous method (i.e. one that doesn't return a Task or Task<T> ) but you want to call an async method. However, without marking the method as async you can't use the await keyword.

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.