Async
92 bites tagged Async — interview questions with model answers, and 60-second explainers.
Returning a Promise from a Native Module Method
The exported method takes resolve and reject as its last parameters; do the async work off the main thread, then settle exactly once with a result or an error. native module async bridging.
Handling async API calls in Redux
Middleware intercepts dispatched actions, Thunk dispatches functions for simple flows, Saga uses generators for complex orchestration. understanding of async side effects in a synchronous store.
BackgroundTasks dependency vs response.background
The injected BackgroundTasks parameter lets endpoints and dependencies stack tasks and is the common path; response.background attaches a single Starlette task when you return a Response object… Two ways to defer work after a response.
Propagating a correlation ID without parameter passing
Middleware reads or generates the header, stores it in a contextvars.ContextVar, service code reads it anywhere, and logging filters inject it. Ambient request-scoped context in async code.
MongoDB async ODM vs SQLAlchemy sessions
Motor client as a connection pool with no SQLAlchemy-style session or transaction; Beanie document models over Motor; initialize once at startup and await find queries. NoSQL data access in async FastAPI.
Callback hell and how to refactor it
Deeply nested callbacks (pyramid of doom) hurt readability and error handling, refactor with promises or async/await. managing async control flow readably.
Blocking versus non-blocking I/O in Node
Blocking calls halt the thread until done, non-blocking returns immediately and notifies via callback or promise, fs.readFileSync versus fs.readFile. core async model understanding.
Microtask versus macrotask execution order in Node
NextTick drains before promises, both microtask queues flush fully between each macrotask, timers and setImmediate are macrotasks. precise grasp of event loop ordering.
Role of libuv in the Node.js runtime
Libuv provides the event loop, a thread pool for blocking work, and OS async I/O abstractions. understanding of how Node achieves async I/O. claiming V8 itself runs the event loop or that Node is fully single-threaded.
Testing async Promise-returning code in Jest
Return or await the promise; use await expect(...).resolves/rejects, or await the value directly. Whether you make async assertions actually run before the test ends.
Propagating async errors to Express error handlers
Express does not auto-catch rejected promises, so catch and call next(err), or wrap handlers in an asyncHandler that forwards rejections; Express 5 awaits handlers automatically. async error forwarding.
fs.readFileSync vs fs.readFile
Sync blocks the event loop and returns directly, async takes a callback or promise, only sync is safe at startup. grasp of blocking vs non-blocking I/O. using readFileSync inside a request handler.
Handling async errors in Express middleware
Await inside try/catch and call next(err) on failure, or wrap the handler in an async error adapter; never let a rejected Promise go uncaught. routing async errors into Express.
Running independent requests with Promise.all and race
Start all requests then await Promise.all to get all results or fail fast on first rejection; use Promise.race when only the fastest settled result matters. concurrent Promise combinators.
Output order of sync, microtask, and macrotask
C runs first synchronously, then B drains from the microtask queue, then A from the macrotask queue. microtask vs macrotask priority. claiming setTimeout(0) beats the Promise, or that order is random.
The three states of a JavaScript Promise
Pending, fulfilled, rejected; settle is one-way and final; create with the executor calling resolve or reject, consume with then and catch. fundamentals of Promise lifecycle.
Order of the Node.js event loop phases
Timers, pending callbacks, poll, check, close phases in order; I/O completion runs in poll. understanding of libuv's loop, not just async vibes. claiming Node is single-phase or fully multithreaded.
Offload long-running tasks from web requests
Enqueue the job to a queue, return immediately, process with separate workers, report status out of band. async background-job architecture. doing the work in the request thread or fire-and-forget threads.
Testing async code and completion handlers in XCTest
Create an expectation, fulfill it inside the completion handler, call wait with a timeout, or use async test methods. knowledge of waiting for asynchronous work in tests.
Why Pin is needed for self-referential Futures
Async blocks compile to state machines that can hold references into their own storage; Pin guarantees the value will not move so those internal pointers stay valid across polls. deep grasp of async internals.
Rust async/await vs Go goroutines
Go schedules goroutines on a built-in runtime transparently; Rust futures are inert until polled by an external runtime like Tokio, and async colors functions. async execution models.
How do you debounce input for API validation in Vue or Angular?
Tests reactive stream control and cancellation. A strong answer uses debounceTime at 300ms, switches with switchMap, and handles loading and error states. Red flag: using setTimeout without cleanup or ignoring race conditions.
Observable: Angular's Push-Based Data Stream
An Observable is a lazy push collection that emits values over time. Angular uses it for HTTP and events, letting components react instead of polling. Forgetting to unsubscribe leaks memory and keeps destroyed components alive.
Write an IndexedDB add function with transaction error handling
Tests IndexedDB request-transaction lifecycle and event-driven error propagation. Answers open a transaction, call add(), and wire onsuccess/onerror on the request plus onabort/onerror on the transaction. Red flag: ignoring onabort or duplicate-key throws.
Get Async bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.