PHPackages                             tourze/yield-breakable-caller - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/yield-breakable-caller

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tourze/yield-breakable-caller
=============================

BreakableCaller, using Yield

0.0.2(11mo ago)02211MITPHPPHP ^8.1CI passing

Since Apr 27Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/yield-breakable-caller)[ Packagist](https://packagist.org/packages/tourze/yield-breakable-caller)[ RSS](/packages/tourze-yield-breakable-caller/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

YieldBreakableCaller
====================

[](#yieldbreakablecaller)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/fa87a7068a42b7cd0f98d21afb254c39ac495fa34e3d67818457a40c89ebd697/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7969656c642d627265616b61626c652d63616c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yield-breakable-caller)[![Total Downloads](https://camo.githubusercontent.com/d4df34bebebfb6982743eedd2da9d41cdf51d99be8495146f2aa3592020d2731/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f7969656c642d627265616b61626c652d63616c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yield-breakable-caller)[![PHP Version](https://camo.githubusercontent.com/61cd59f0d83a07fd46aa0f9c271ba910faf85661fe3a285a52504979d74a57eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f7969656c642d627265616b61626c652d63616c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yield-breakable-caller)[![License](https://camo.githubusercontent.com/43491d8a5e20860c6777077528c218bb80d11f65a3c61fc34c5ec245cc0a6ea5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f75727a652f7969656c642d627265616b61626c652d63616c6c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/tourze/yield-breakable-caller/blob/master/LICENSE)[![Coverage Status](https://camo.githubusercontent.com/e0169f83d4db0df03f5b5acc7322b66ac7b9765b2a52485e5cf57a39ccab2d44/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7969656c642d627265616b61626c652d63616c6c65722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/yield-breakable-caller)

A lightweight PHP library for breakable step-by-step task execution using Generators (yield). Allows interruption of task flow at any step based on custom conditions.

Features
--------

[](#features)

- Step-by-step task execution based on PHP Generator (yield)
- Interrupt task flow at any step by custom logic
- Simple, dependency-free implementation
- Suitable for scenarios requiring controllable breakpoints in process

---

Installation
------------

[](#installation)

- Requires PHP &gt;= 8.1
- Install via Composer:

```
composer require tourze/yield-breakable-caller
```

---

Quick Start
-----------

[](#quick-start)

```
use Tourze\YieldBreakableCaller\BreakableCaller;

$caller = new BreakableCaller();

$task = function () {
    echo "Step 1 executing\n";
    yield;
    echo "Step 2 executing\n";
    yield;
    echo "Step 3 executing\n";
    yield;
    echo "Step 4 executing\n";
};

$shouldContinue = function () {
    static $count = 0;
    $count++;
    return $count < 3; // Interrupt after 3rd step
};

$caller->invoke($task, $shouldContinue);
```

Output:

```
Step 1 executing
Step 2 executing
Step 3 executing

```

---

Documentation
-------------

[](#documentation)

### Core API

[](#core-api)

#### `BreakableCaller::invoke(callable $callback, callable $shouldNext): void`

[](#breakablecallerinvokecallable-callback-callable-shouldnext-void)

- `$callback`: A function returning a generator
- `$shouldNext`: A callback to determine whether to continue after each step

### Behavior

[](#behavior)

- After each `yield`, `$shouldNext` is evaluated. If it returns `false`, all subsequent steps are interrupted.
- Supports empty generators, single-yield generators, and will throw if callback does not return a generator.

---

Contributing
------------

[](#contributing)

We welcome contributions to improve this library. Please follow these guidelines:

- Submit issues for bugs or feature requests
- Follow PSR coding standards
- Write tests for new features
- Update documentation when needed

### Development

[](#development)

1. Clone the repository
2. Install dependencies: `composer install`
3. Run tests: `composer test` or `vendor/bin/phpunit`
4. Run static analysis: `composer phpstan` or `vendor/bin/phpstan analyse`

License
-------

[](#license)

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and updates (if available).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance64

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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 ~27 days

Total

2

Last Release

350d ago

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-yield-breakable-caller/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-yield-breakable-caller/health.svg)](https://phpackages.com/packages/tourze-yield-breakable-caller)
```

###  Alternatives

[daijie/aria2

talk with aria2

726.8k](/packages/daijie-aria2)

PHPackages © 2026

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