Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
01-basics.js fix: basic example blooper Feb 16, 2018
02-try-catch.js task: creating errors in task to improve stack traces Feb 16, 2018
03-sequential-foreach.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
04-sequential-map.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
05-sequential-naive.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
06-sequential-forof.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
07-sequential-for.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
08-sequential-while.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
09-sequential-ordering.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
10-parallel-naive.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
11-parallel.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
12-parallel-ordering.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
13-race.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
14-conditionals.js try/catch + sequential/parallel flow and conditional examples Feb 16, 2018
15-non-blocking.js example showing that await doesn't block event loop Feb 16, 2018
16-nesting.js nesting await example Feb 16, 2018
17-promise-overflow.batches.js perf: adding batching promise overflow example May 7, 2018
17-promise-overflow.js perf: adding promise overflow Feb 16, 2018
18-promise-interaction.js promise-interaction: adding memoize and event examples Feb 23, 2018
19-promise-interaction.memoize.js promise-interaction: adding memoize and event examples Feb 23, 2018
20-promise-interaction.event.js promise-interaction: adding memoize and event examples Feb 23, 2018
21-promise-interaction.retry.js promise-interaction: adding retry example Feb 23, 2018
README.md docs: adding resources Feb 16, 2018
package.json promise-interaction: adding retry example Feb 23, 2018
util.js util: adding sleep and stay alive functionality May 7, 2018

README.md

async-wait-box

become a patron

Examples to show techniques to archieve particular tasks via async/await.

Ordered by level of complexity.

Quick async/await Overview

async marks a function as asynchronous, the function will always return a Promise, resolving with the return value. await handles Promises inside the async function, making the function’s inner logic synchronous.

async/await only blocks execution of that function, however other functions can still execute while it is waiting. Thus developers still can leverage Node.js concurrency.

Getting Started

To ensure all dependencies are installed run the below after cloning the repo.

npm install

Usage

Run each example directly i.e. node 01-basics.js and edit to your delight and observe what changed.

Debugging

To see how promises get executed/resolved/rejected under the hood run with the DEBUG=task env var, i.e.:

DEBUG=task node 01-basics.js

To run an example in your browser run it with the included budo, i.e.:

npm run budo -- 01-basics.js

This allows you to add breakpoints, observe stack traces, etc. to understand how things work under the hood and also to convince yourself that async/await code is easily debuggable.

Resources

LICENSE

MIT