All skills
sergiodxa avatar

/frontend-async-best-practices

@4d1d816

Async/await and Promise optimization guidelines. Use when writing, reviewing, or refactoring asynchronous code to eliminate waterfalls and maximize parallelism. Triggers on tasks involving data fetching, loaders, actions, or Promise handling.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-async-best-practices

This session only. Nothing lands on disk.

rulesdependencies.md

≈466 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Dependency-Based Parallelization

When operations have partial dependencies, start independent work immediately and chain dependent work. This maximizes parallelism without waiting unnecessarily.

Problem: profile waits for config unnecessarily

const [user, config] = await Promise.all([fetchUser(), fetchConfig()]);
const profile = await fetchProfile(user.id); // config already done, wasted time

Timeline: [user + config] -> [profile] (2 sequential steps)

Solution: chain dependent operations, parallelize independent ones

const userPromise = fetchUser();
const profilePromise = userPromise.then((user) => fetchProfile(user.id));

const [user, config, profile] = await Promise.all([
  userPromise,
  fetchConfig(),
  profilePromise,
]);

Timeline: [user + config] and [user -> profile] run in parallel (profile starts as soon as user completes, doesn't wait for config)

More complex example:

// user -> profile -> settings (chain)
// config (independent)
// permissions depends on user (parallel with profile)

const userPromise = fetchUser();
const profilePromise = userPromise.then((u) => fetchProfile(u.id));
const settingsPromise = profilePromise.then((p) => fetchSettings(p.id));
const permissionsPromise = userPromise.then((u) => fetchPermissions(u.id));

const [user, config, profile, settings, permissions] = await Promise.all([
  userPromise,
  fetchConfig(),
  profilePromise,
  settingsPromise,
  permissionsPromise,
]);

Key insight: Create all promises first, then Promise.all() at the end. Each promise starts executing immediately when created, and .then() chains execute as soon as their dependency resolves.

Source: SKILL.md on GitHub

1 warning14d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    This skill is an educational resource containing best practice guidelines for optimizing asynchronous JavaScript and React code. No security risks, malicious code, or unauthorized operations were detected.

  • Socket14d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer7mo

    6/6 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4d1d816. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-async-best-practices