defer-await-until-needed

Defer await operations in JavaScript/TypeScript until conditionally required.

Updated Feb 10, 2026
One-click install
npx skills add https://github.com/ihj04982/my-cursor-settings --skill defer-await-until-needed
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defer-await-until-needed
Source: https://github.com/ihj04982/my-cursor-settings/tree/main/skills/defer-await-until-needed
Command: npx skills add https://github.com/ihj04982/my-cursor-settings --skill defer-await-until-needed

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses inefficient asynchronous code patterns where await operations block code paths that do not actually require the awaited result, leading to unnecessary delays.

Core Features & Use Cases

  • Lazy Await: Moves await calls into specific code branches, ensuring they are only executed when their results are needed.
  • Performance Optimization: Prevents blocking of unrelated code execution, improving overall application responsiveness.
  • Use Case: Refactor an async function to fetch user data only when the skipProcessing flag is false, rather than fetching it upfront and potentially wasting time if processing is skipped.

Quick Start

Refactor the provided TypeScript code to defer the await operation until it is strictly necessary.

Frequently Asked Questions about defer-await-until-needed

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize async/await performance in TypeScript when some execution paths skip the awaited result?

To optimize async/await performance in TypeScript, defer await operations by moving them into specific conditional branches. This prevents blocking execution paths that do not actually require the awaited result, improving overall responsiveness.

Why does awaiting an async call upfront slow down my JavaScript function if the result is only conditionally needed?

Awaiting an async call upfront creates unnecessary blocking because the JavaScript engine waits for the promise to resolve even if subsequent conditional logic skips that result. Deferring the await until strictly necessary eliminates this wasted time.

What is the best way to refactor JavaScript code to fetch data only when a processing flag is false?

The best way to conditionally fetch data in JavaScript is to place the await call inside the conditional branch where the processing flag is false, ensuring the fetch operation only executes when its results are strictly necessary.

Can I use deferred await to improve application responsiveness in functions with multiple execution paths?

Yes, you can use deferred await to improve application responsiveness in functions with multiple execution paths. By placing await calls only within the relevant branches, you prevent unnecessary blocking of unrelated code execution.

When should I avoid moving await operations into conditional branches in my async functions?

You should avoid moving await operations into conditional branches if all subsequent execution paths within the async function strictly depend on the awaited result, as deferring provides no performance benefit when the blocking is unavoidable.