mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-06 03:18:18 +01:00
67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace danog\Loop\Generic {
|
||
|
|
||
|
use danog\Loop\GenericLoop as LoopGenericLoop;
|
||
|
use danog\Loop\PeriodicLoop as LoopPeriodicLoop;
|
||
|
use danog\MadelineProto\Tools;
|
||
|
use Generator;
|
||
|
|
||
|
/**
|
||
|
* @deprecated Please use danog\Loop\PeriodicLoop instead
|
||
|
*/
|
||
|
class PeriodicLoop extends LoopPeriodicLoop {
|
||
|
public function __construct(callable $callback, string $name, ?int $interval)
|
||
|
{
|
||
|
if ($callback instanceof \Closure) {
|
||
|
try {
|
||
|
$callback = $callback->bindTo($this);
|
||
|
} catch (\Throwable) {
|
||
|
// Might cause an error for wrapped object methods
|
||
|
}
|
||
|
}
|
||
|
parent::__construct(
|
||
|
function ($_) use ($callback) {
|
||
|
$result = $callback();
|
||
|
if ($result instanceof Generator) {
|
||
|
$result = Tools::consumeGenerator($result);
|
||
|
}
|
||
|
return $result;
|
||
|
},
|
||
|
$name,
|
||
|
$interval ? $interval/1000 : null
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @deprecated Please use danog\Loop\GenericLoop instead
|
||
|
*/
|
||
|
class GenericLoop extends LoopGenericLoop {
|
||
|
public function __construct(callable $callback, string $name)
|
||
|
{
|
||
|
if ($callback instanceof \Closure) {
|
||
|
try {
|
||
|
$callback = $callback->bindTo($this);
|
||
|
} catch (\Throwable) {
|
||
|
// Might cause an error for wrapped object methods
|
||
|
}
|
||
|
}
|
||
|
parent::__construct(
|
||
|
function ($_) use ($callback) {
|
||
|
$result = $callback();
|
||
|
if ($result instanceof Generator) {
|
||
|
$result = Tools::consumeGenerator($result);
|
||
|
}
|
||
|
if (is_int($result) || is_float($result)) {
|
||
|
$result /= 1000;
|
||
|
}
|
||
|
return $result;
|
||
|
},
|
||
|
$name
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|