V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zhaoyc2018
V2EX  ›  PHP

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

  •  
  •   zhaoyc2018 · Dec 23, 2020 · 1618 views
    This topic created in 1951 days ago, the information mentioned may be changed or developed.

    有点不懂这是怎么回事

    <?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

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5641 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 08:30 · PVG 16:30 · LAX 01:30 · JFK 04:30
    ♥ Do have faith in what you're doing.