当前位置:网站首页>About the swoole coroutine container

About the swoole coroutine container

2022-06-25 23:48:00 ndrandy

To use a coroutine API, Must be in the process container , So how to create a collaboration container ? Outermost layer go In closure , perhaps \Co\Run() In closure , You have created a coroutine container

<?php

go(function(){ // This is used here \Co\Run Equally effective 

// In the current closure , Even if the process environment , In general , Root Xiecheng cid = 1

 for ($i=0;$i<10;$i++) {
      go(function(){
         // Subprocess environment 
      })
 } 


 // Here, you must wait until the execution of all sub process environments is completed 
});


// The current location is not a co process environment ,  This is where the code ends 

 

  Bear in mind !!! In a collaborative environment , Never use sleep, Otherwise, the global or static variables are dirty , Whether or not you use the context manager to isolate the process .

The current schedule co::sleep() It will only affect the current collaboration process , It will not affect the switching time of the coordination process scheduling and the running time of other coordination processes

There is nesting in the process , The parent process must wait for all the child processes to run , To quit  

原网站

版权声明
本文为[ndrandy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206252056449061.html