condition-based-waiting

Poll conditions instead of timeouts to wait for state changes in tests.

4|Updated Oct 3, 2025
One-click install
npx skills add https://github.com/apexbusiness-systems/APEX-OmniHub --skill condition-based-waiting-apexbusiness-systems
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/apexbusiness-systems/APEX-OmniHub/tree/main/.cursor/superpowers/skills/condition-based-waiting
Command: npx skills add https://github.com/apexbusiness-systems/APEX-OmniHub --skill condition-based-waiting-apexbusiness-systems

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Wait for actual state changes in tests instead of guessing with arbitrary delays, reducing flakiness and CI failures caused by timing variance.

Core Features & Use Cases

  • Condition-based waiting: replace timeouts with polling until a condition evaluates to true.
  • Reliability across async flows: works with asynchronous operations, events, and background tasks to produce deterministic results.
  • Use Case: Imagine a test that waits for a background job to reach a READY state before asserting outcomes.

Quick Start

Start by replacing explicit sleeps with a waitFor-style pattern that polls a condition. Example commands:

  • waitFor(() => data.ready)
  • waitForEvent(threadManager, id, 'READY') // if applicable
  • waitFor(() => items.length > 0) // wait for collection population

Frequently Asked Questions about condition-based-waiting

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

FAQPage Schema
How do I fix flaky tests caused by arbitrary timeouts and unpredictable timing?

Condition-based waiting fixes flaky tests by replacing arbitrary timeouts with polling that waits for actual state changes. This ensures deterministic outcomes by continuously checking until a specific condition evaluates to true.

What is the best way to wait for an asynchronous operation to reach a READY state in integration tests?

The best way to wait for an asynchronous operation is using a waitForEvent pattern that polls for specific state changes. This provides a generic condition-based waiting mechanism with a timeout to handle unpredictable background job timing.

How do I wait for a collection to populate during async testing without using explicit sleeps?

You wait for collection population during async testing by implementing a waitFor condition that polls until items achieve the desired length. This replaces explicit sleeps with polling that checks if the collection state matches your criteria.

Does condition-based waiting work for both unit and integration tests across UI events?

Yes, condition-based waiting works for both unit and integration tests across UI events, asynchronous operations, and long-running processes. It provides specialized variants like waitForEvent and waitForEventMatch to handle diverse unpredictable timing scenarios.

Why does polling for state changes produce more deterministic test results than fixed delays?

Polling for state changes produces deterministic test results because it waits for actual conditions to be met rather than relying on fixed delays that may expire too early or waste time. This timing variance reduction eliminates CI failures.