liveBook · Manning

Async function

As explained in Secrets of the JavaScript Ninja, Second Edition

A JavaScript function marked as asynchronous that can use await and returns a promise.

An async function marks work that depends on asynchronous values. It returns a promise, and `await` lets the function pause for a result without blocking the UI. section 6.4.1

Async/await provides built-in language support for coordinating generators and promises, avoiding a reusable helper that would otherwise resume a generator as promises settle. section 6.4 section 6.4.1

Fetch dependent mission data

Await JSON for a ninja, that ninja’s missions, and a mission’s details in sequence; use try/catch to handle a failed request. section 6.4 section 6.4.1

How Secrets of the JavaScript Ninja, Second Edition covers it

How deep it goes
Explains async and await syntax and their role in coordinating promises, while leaving the underlying machinery out of the code.
Examples
Demonstrates sequential JSON requests for ninja, mission, and mission-detail data, with try/catch error handling.
What it assumes
Builds on generators and promises rather than teaching their mechanics from scratch.
What you can do after
Apply async/await to sequence dependent requests without blocking and handle failures with try/catch.
How it connects
Connects async functions with promises and generators.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Second Edition. The section links point to the parts of the book it draws on.