Skip to main content

Async Await

@serverSerrverlesskiy

There is a special syntax работы for working with promises called async / await.

Creating an asynchronous function#

creature

An asynchronous function⚙️ is defined by an asynchronous function expression⚙️. The basic function⚙️ looks like this:

async function foo() {
const value = await somePromise()
return value
}

We define a function⚙️ to be asynchronous using async. This keyword can be used with any syntax for a function declaration:

// Function Declaration
async function foo() { ... }
// Function Expression
const foo = async function () { ... }
// Arrow function
const foo = async () => { ... }
// Class methods
class Bar {
async foo() { ... }
}

Stops

Once we have defined the function as asynchronous, we can use the await keyword. This keyword is placed before a promise call, it pauses the function until the promise is fulfilled or rejected.

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Contributors ✨#

Thanks goes to these wonderful people (emoji key):


AlisaNasibullina

📖

Dmitriy Vasilev

💵

Resoner2005

🐛 🎨

Become a Patron!