V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhaoyc2018
V2EX  ›  PHP

parallel 多线程函数中返回,出现错误 caller must retain reference to Future

  •  
  •   zhaoyc2018 · 2020-12-23 21:39:42 +08:00 · 1161 次点击
    这是一个创建于 1220 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有点不懂这是怎么回事

    <?php
    use parallel\Runtime;
    use parallel\Channel;
    
    $thread_function = function (Channel $ch) {
    	echo "test1\n";
    
    	return;
    
    	$ch->send("test2\n");
    };
    
    $r1 = new Runtime();
    $ch1 = new Channel();
    
    $args = array();
    $args[0] = $ch1;
    $r1->run($thread_function, $args);
    
    echo $ch1->recv();
    
    $ch1->close();
    

    PHP Fatal error: Uncaught parallel\Runtime\Error\IllegalReturn: return on line 3 of task ignored by caller, caller must retain reference to Future in D:\Desktop\test.php:18

    请问如何在该函数中中断执行?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1010 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:56 · PVG 06:56 · LAX 15:56 · JFK 18:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.