Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timer parameter passing #508

Merged
merged 3 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/framework/src/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
class Timer
{
/**
* @param int $msec
* @param int $msec
* @param array|callable $callback
* @param array ...$params
* @param array ...$params
*
* @return int
* @throws Exception\SwoftException
Expand Down Expand Up @@ -48,17 +48,17 @@ public static function tick(int $msec, $callback, ...$params): int
}

/**
* @param int $msec
* @param int $msec
* @param array|callable $callback
* @param array ...$params
* @param array ...$params
*
* @return int
* @throws Exception\SwoftException
*/
public static function after(int $msec, $callback, ...$params): int
{
$items = self::getLogItems();
return SwooleTimer::after($msec, function () use ($callback, $items) {
return SwooleTimer::after($msec, function () use ($callback, $items, $params) {

try {
// Before
Expand All @@ -68,7 +68,7 @@ public static function after(int $msec, $callback, ...$params): int
self::initItems($items);

// Callback
PhpHelper::call($callback, 1);
PhpHelper::call($callback, ...$params);

// After
Swoft::trigger(SwoftEvent::TIMER_AFTER_AFTER);
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function stats(): array
*/
private static function getLogItems(): array
{
$data = [];
$data = [];
$items = Log::getLogger()->getItems();

foreach ($items as $item) {
Expand Down
4 changes: 2 additions & 2 deletions src/framework/test/unit/TimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function testAfter()
{
$a = 1;
Timer::after(500, function ($a) {
$this->after++;
$this->after = $a;
}, $a);

Co::sleep(1);

$this->assertEquals($this->after, 1);
}
}
}