innmind/async-time-warp

This package is abandoned and no longer maintained. The author suggests using the innmind/mantle package instead.

1.0.0 2023-02-11 12:48 UTC

This package is auto-updated.

Last update: 2023-11-06 06:41:05 UTC


README

Build Status codecov Type Coverage

Async implementation of innmind/time-warp to allow switching to another task when halting the current process.

Installation

composer require innmind/async-time-warp

Usage

use Innmind\Async\TimeWarp\Halt;
use Innmind\TimeContinuum\Earth\{
    Clock,
    Period\Second,
};
use Innmind\Mantle\{
    Source\Predetermined,
    Suspend,
    Forerunner,
};

$clock = new Clock;
$source = Predetermined::of(
    static function(Suspend $suspend) use ($clock) {
        $halt = Halt::of($clock, $suspend);

        $halt(new Second(2));

        echo 'World !';
    },
    static function(Suspend $suspend) use ($clock) {
        $halt = Halt::of($clock, $suspend);

        $halt(new Second(1));

        echo 'Hello ';
    },
);

Forerunner::of($clock)(null, $source); // will print "Hello World !" in 2 seconds