Re: Re: PHP True Async RFC

From: Date: Mon, 10 Mar 2025 11:36:50 +0000
Subject: Re: Re: PHP True Async RFC
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-126692@lists.php.net to get a copy of this message
>function par_map(iterable $it, callable $c) { > $result = []; > async { > foreach ($it as $val) { > $result[] = $c($val); > } > } >return $result; >} If the assumption is that each call can be asynchronous and all elements need to be processed, the only proper tool is a concurrent iterator. Manually using a foreach loop is not the best idea because the iterator does not necessarily create a coroutine for each iteration. And, of course, such an iterator should have a getFuture method that allows waiting for the result. Yes, Kotlin has an explicit blocking Scope, but I don’t see much need for it. So far, all the cases we’re considering fit neatly into a framework: 1. I want to launch a coroutine and wait: await spawn 2. I want to launch a coroutine and not wait: spawn 3. I want to launch a group of coroutines and wait: await CoroutineScope 4. I want to launch a group of coroutines and not wait: spawn 5. I want a concurrent iteration: special iterator. What else are we missing?

« previous php.internals (#126692) next »