pe/component-loop

此包的最新版本(v1.1.0)没有可用的许可证信息。

定时器循环

v1.1.0 2022-07-23 11:48 UTC

This package is auto-updated.

Last update: 2024-08-23 15:58:31 UTC


README

以下版本的PHP受到支持。

  • PHP 7.4+

安装

要安装,请使用composer

php composer.phar require pe/component-loop

用法

用于运行一些可调用的延迟或重复的循环,例如

namespace PE\Component\Loop;

$loop = new Loop();

// For delayed run callable add singular timer
$loop->addSingularTimer(0.1, static function (Loop $loop, Timer $timer) {
    // Do some work delayed by 0.1 second
});

// For repeated run callable add periodic timer
$loop->addPeriodicTimer(0.5, static function (Loop $loop, Timer $timer) {
    // Do some work at each 0.5 second
});

// For stop loop execution you may add special timer
$loop->addSingularTimer(60, static function (Loop $loop) {
    $loop->stop();
});

// Run loop
$loop->run();