January 2020
Intermediate to advanced
470 pages
11h 13m
English
Let's start with a simple quiz: are the results what you expected? Let's look at a couple of examples of code involving async calls and maybe we'll see some unexpected results. First, let's look at a common straightforward sequence of async calls:
(async () => { console.log("START SEQUENCE"); const x1 = await fakeAPI(1000, 1); useResult(x1); const x2 = await fakeAPI(2000, 2); useResult(x2); const x3 = await fakeAPI(3000, 3); useResult(x3); const x4 = await fakeAPI(4000, 4); useResult(x4); console.log("END SEQUENCE");})();
If you run this code, you'll get the following results, which are surely what you would expect—a START SEQUENCE text, four individual lines with the results of the fake API calls, and a final END SEQUENCE ...
Read now
Unlock full access