JavaScript async/await in 2017: Handling errors and concurrency
A historical look at ECMAScript 2017 async functions, with practical error and concurrency checks.
Archive retrospective · Topic year 2017
In this article
What was standardized in 2017?
The eighth edition of ECMA-262, published in June 2017, incorporated async functions into the JavaScript language standard. That date does not mean all browsers received support on the same day: engines shipped features on different schedules, sometimes earlier. In an October 2, 2017 article, Mathias Bynens discussed how suspended async functions could help reconstruct asynchronous stack traces, while describing the limits of the engine implementation at the time. His forward-looking performance discussion is not a guarantee for every current runtime. This is a historical feature explained with a present-day error-handling exercise.
Promises and suspension
An async function returns a Promise. Inside it, await suspends that function's continuation until the awaited value settles; it does not stop the entire JavaScript thread. A rejected Promise can be caught at the await expression. The caller must still handle the Promise returned by the async function. Network requests and timers are provided by the host environment: the language specification itself does not supply a particular HTTP client. This distinction matters when moving code between browsers and servers. Async syntax does not make work automatically parallel or eliminate its cost.
Example: read two sources
Suppose an order screen needs a price and stock level from separate APIs. A small example is: async function screen(getPrice, getStock) { const [price, stock] = await Promise.all([getPrice(), getStock()]); return { price, stock }; }. Independent calls start in the same phase, and the function returns after both complete. At the calling site, use a surrounding async context and handle rejection: try { const data = await screen(getPrice, getStock); } catch (error) { /* show a safe message */ }. Promise.all rejects when one member rejects. Do not assume that the other operation is automatically cancelled.
Order and dependencies
If the second request needs the result of the first, await the first result before starting the second. For instance, check a customer identity before requesting that customer's private orders. Waiting sequentially for independent steps can increase elapsed time, while unlimited concurrency can overwhelm a service. Instead of putting an unbounded list into Promise.all, design a queue with an explicit concurrency limit. Write down the data dependencies before optimizing. Measure duration and resource usage with a small test; results depend on runtime, network and service conditions.
Errors, timeouts and cancellation
Use try/catch for errors raised in the awaited flow. A Promise that is started and abandoned needs its own rejection handling. Network timeout and cancellation behavior depends on the host API; check support for tools such as AbortController in the target environment. Even after a client timeout, the server may have processed the request. For a payment or order, design a server-side idempotency key and a way to query the result before retrying. Avoid exposing tokens, personal data or internal addresses in the message shown to the user.
Stack traces in historical context
Bynens argued in 2017 that suspension could make it easier for an engine to reconstruct an asynchronous call chain. His article also stated that the proposed optimization had not yet been implemented in V8 at that time. It should therefore not be read as evidence of the same speed improvement in every modern engine. Check source maps, stack traces and error collection in the runtime you actually deploy. Reject a controlled test operation and inspect the resulting call chain. Review source-map access so production diagnostics do not accidentally expose private code.
Cost and security boundaries
Concurrent calls may reduce elapsed waiting time but can create more simultaneous connections, API requests and billable operations. State the request count and concurrency cap in the test plan. Keep sensitive values out of error logs and send only necessary, masked fields to monitoring. Do not trust a client-supplied price or authorization decision without server-side validation. Adapt copied examples to your authentication, quotas, cancellation and retry contract. A syntax improvement does not replace these operational decisions, and a benchmark from another application does not establish your own capacity.
Practical verification
Identify supported browser and server versions, then verify any build or compatibility strategy. Test two successful requests, one rejection, a slow response and a retry. Observe that independent calls start together, dependent calls run in the required order and the user receives a safe failure state. Verify on the server that a repeated side-effecting request does not create a second record. Record request count, elapsed time and error trace. Treat the result as evidence for the tested versions and environment, not a universal performance claim.
Source event:
Mathias Bynens — kişisel teknik yayın, Belçika, 2 Ekim 2017: asenkron hata izi ↗Ecma International — ECMA-262 sekizinci baskı, İsviçre, Haziran 2017: dil standardı ↗
Reader discussion
Which bottleneck would you expect as this solution scales?
No comments yet. Be the first to contribute.
Write a comment