> Edmond Dantes <[email protected]> hat am 22.11.2025 13:01 CET geschrieben:
> 
>  
> Hello
> 
> > function return types should not depend on the outside context (spawn, 
> > hook, ini, etc.) because when the code gets more complex, it's very hard to 
> > find the outside context.
> 
> What does “outside context” mean?
> 
> I just want to understand the practical use of functions with Promise.
> The code above makes sense only if there is awaitAll.
> 
> $promise1 = file_get_content_async("file1.txt");
> $promise2 = file_get_content_async("file2.txt");
> $promise3 = file_get_content_async("file3.txt");
> 
> awaitAll($promise1, ....);
> 
> But you can achieve exactly the same effect without special functions.
> The only difference is that the _async function inside might be
> optimized in some way.
> Or is there something else?
> 
> ---
> Ed

Hello,

basically in $result = foo(spawn(bar(baz(file_get_contents())))); 
file_get_contents() receives outside context from spawn() to turn into async 
mode. Also foo(), bar(), baz() can be in different namespaces, different 
classes, so by looking at the code calling file_get_contents(), it's not clear 
if the result is sync or async.

Another example:

$foo = file_get_contents('foo.txt');
$result = foo($foo);

should be equal to:

$result = foo(file_get_contents('foo.txt'));


but having:

$foo = file_get_contents('foo.txt'); // sync
$result = spawn($foo); // error because $foo is string

would not be eqaul to:

$result = spawn(file_get_contents('foo.txt')); // async

Best Regards
Thomas

Reply via email to