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

批量执行 task 功能无效 #416

Open
huangdijia opened this issue Sep 22, 2022 · 2 comments
Open

批量执行 task 功能无效 #416

huangdijia opened this issue Sep 22, 2022 · 2 comments

Comments

@huangdijia
Copy link

// routes/web.php

$router->get('/', function() {
    $tasks[] = mt_rand(1000, 9999); //任务1
    $tasks[] = mt_rand(1000, 9999); //任务2
    $tasks[] = mt_rand(1000, 9999); //任务3
    var_dump($tasks);

    //等待所有Task结果返回,超时为10s
    $results = app('swoole')->taskWaitMulti($tasks, 10.0);

    if (! isset($results[0])) {
        echo "任务1执行超时了\n";
    }
    if (isset($results[1])) {
        echo "任务2的执行结果为{$results[1]}\n";
    }
    if (isset($results[2])) {
        echo "任务3的执行结果为{$results[2]}\n";
    }
});

执行结果:任务1执行超时了

@hhxsv5
Copy link
Owner

hhxsv5 commented Sep 26, 2022

因为LaravelS中封装了Hhxsv5\LaravelS\Swoole\Task\Task Hhxsv5\LaravelS\Swoole\Task\Event,会忽略其他类型的Task,onTask中不会return结果,故taskWaitMulti()返回的是false。

关于taskWaitMulti(),LaravelS应该可以封装一个MultiTask对象,这个我本地测试看看,如果可行,会发布新版支持。

@huangdijia
Copy link
Author

节后能支持吗😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants