PHPackages                             wikimedia/wait-condition-loop - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wikimedia/wait-condition-loop

ActiveLibrary

wikimedia/wait-condition-loop
=============================

Wait loop that reaches a condition or times out

v2.0.2(4y ago)5695.5k↑18.7%1GPL-2.0-or-laterPHPPHP &gt;=7.2.9

Since Sep 30Pushed 2mo ago9 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-WaitConditionLoop)[ Packagist](https://packagist.org/packages/wikimedia/wait-condition-loop)[ Docs](https://www.mediawiki.org/wiki/WaitConditionLoop)[ RSS](/packages/wikimedia-wait-condition-loop/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (6)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/b1e69980456535da2ae6f0f06b8d86a33d51864452c77fa735d0f5be07626433/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f776169742d636f6e646974696f6e2d6c6f6f702f762f737461626c652e737667)](https://packagist.org/packages/wikimedia/wait-condition-loop) [![License](https://camo.githubusercontent.com/9b1c370a855492db5b0d8c02891a80fa066bf536b707af561a519a72e86c5221/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f776169742d636f6e646974696f6e2d6c6f6f702f6c6963656e73652e737667)](https://packagist.org/packages/wikimedia/wait-condition-loop)

Wait Condition Loop for PHP
===========================

[](#wait-condition-loop-for-php)

This class is used for waiting on a condition to be reached, with the ability to specify a timeout. The condition is considered reached when the condition callback returns CONDITION\_REACHED or true. CONDITION\_ABORTED can also be used to stop the loop.

Additionally, "work" callbacks can be injected to prepare useful work instead of simply having the current thread sleep or block on I/O. The loop will run one of these callbacks on each iteration of checking the condition callback, as long as there are any left to run.

The loop class will automatically either retry the condition or usleep() before retrying it, depending on CPU usage. Low CPU usage and significant real-time passage is used to detect whether the condition callback appears to use blocking I/O. Use of usleep() will not occur until all of the "work" callbacks have run. This means that the condition callback can either be an "instant" CPU-bound check or a blocking I/O call with a small timeout. Both cases should automatically work without CPU intensive spin loops.

Additional documentation about the library can be found on [mediawiki.org](https://www.mediawiki.org/wiki/WaitConditionLoop).

Usage
-----

[](#usage)

```
// Pre-compute some value that will be needed later
$result = null;
$workCallback = function () use ( &$result ) {
    $result = ( $result !== null ) ? $result : $this->doWork();

    return $result
}

$loop = new WaitConditionLoop(
    function () use ( ... ) {
        if ( ... ) {
            // Condition reached; stop loop
            return WaitConditionLoop::CONDITION_REACHED;
        }
        // Condition not reached; keep checking
        return WaitConditionLoop::CONDITION_CONTINUE;
    },
    3.0, // timeout in seconds
    [ $workCallback ]
);
$status = $loop->invoke(); // CONDITION_* constant

// Call $workCallback as needed later
```

Running tests
-------------

[](#running-tests)

```
composer install
composer test

```

---

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance57

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~447 days

Total

5

Last Release

1729d ago

Major Versions

v1.0.1 → v2.0.02021-02-11

PHP version history (2 changes)v1.0.0PHP &gt;=5.5.9

v2.0.0PHP &gt;=7.2.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

![](https://www.gravatar.com/avatar/a91173408bf645b6ff78a309a9e55bde405d29c72e2b1ae8ec9f9df1225f76c3?d=identicon)[Krinkle](/maintainers/Krinkle)

---

Top Contributors

[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (12 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (8 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (7 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (5 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (4 commits)")[![ebernhardson](https://avatars.githubusercontent.com/u/558434?v=4)](https://github.com/ebernhardson "ebernhardson (1 commits)")[![AaronSchulz](https://avatars.githubusercontent.com/u/1020708?v=4)](https://github.com/AaronSchulz "AaronSchulz (1 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")[![ricordisamoa](https://avatars.githubusercontent.com/u/4588496?v=4)](https://github.com/ricordisamoa "ricordisamoa (1 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-wait-condition-loop/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-wait-condition-loop/health.svg)](https://phpackages.com/packages/wikimedia-wait-condition-loop)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
