File tree Expand file tree Collapse file tree 4 files changed +27
-1
lines changed
Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1717 "skrtdev\\ async\\ " : " src/"
1818 },
1919 "files" :[
20- " src/range.php"
20+ " src/range.php" ,
21+ " src/helpers.php"
2122 ]
2223 }
2324}
Original file line number Diff line number Diff line change 1+ <?php
2+ require '../vendor/autoload.php ' ;
3+
4+ async (function (){
5+ sleep (3 );
6+ echo 'Wow, this seems to be async ' , PHP_EOL ;
7+ });
8+
9+ echo 'Hello world ' , PHP_EOL ;
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ class Pool{
1616 private bool $ is_resolving_queue = false ;
1717 private bool $ need_tick = true ;
1818
19+ protected static self $ default_pool ;
20+
1921 public function __construct (?int $ max_childs = null , bool $ kill_childs = true )
2022 {
2123 if (!extension_loaded ('pcntl ' )){
@@ -254,6 +256,11 @@ public static function isProcessRunning(int $pid): bool
254256 return posix_getpgid ($ pid ) !== false ;
255257 }
256258
259+ public static function getDefaultPool (): self
260+ {
261+ return static ::$ default_pool ??= new static ();
262+ }
263+
257264}
258265
259266
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ use skrtdev \async \Pool ;
4+
5+ if (!function_exists ('async ' )){
6+ function async (callable $ callable , ...$ args ){
7+ Pool::getDefaultPool ()->parallel ($ callable , ...$ args );
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments