Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check my parent and child process executed in parrallel?? #107

Closed
developeronboard opened this issue Feb 19, 2020 · 7 comments
Closed

Comments

@developeronboard
Copy link

use Spatie\Async\Pool;
public function save(){
//my parent function goes
//my child process starts
$pool[] = async(function () use($data) {
sleep(3);
})->then(function ($output) {
})->catch(function ($exception) {
});
await($pool);
sleep(3);
}
To check I included sleep(3) in both parent and child process and it takes 6 seconds but i think this was not correct because if it was executed in parallel means it has to take only 3 seconds. Please guide me for this issue.

@brendt
Copy link
Contributor

brendt commented Feb 19, 2020

Please take a look at #97, carefully read the README: https://github.com/spatie/async/blob/master/README.md , and come back if it's still not clear after reading that.

@brendt brendt closed this as completed Feb 19, 2020
@developeronboard
Copy link
Author

am confused..can you explain How to check my parent and child process executed in parrallel??

@brendt
Copy link
Contributor

brendt commented Feb 19, 2020

Have you read up on how this package works?

@developeronboard
Copy link
Author

developeronboard commented Feb 19, 2020

Yeah but able to find some little codes :( can u give a link or explain the parent child process??
[https://dev.to/webong/using-asynchronous-processes-in-php-7io] i refered this link..is this correct?

@brendt
Copy link
Contributor

brendt commented Feb 19, 2020

Maybe this can be of help: https://stitcher.io/blog/asynchronous-php

I'm sorry but I don't have the time to explain the core ideas of async programming in PHP, but I'm sure you can find some good literature online.

@developeronboard
Copy link
Author

Thank you Brendt, if you have time please try to provide codes with some examples in documentation surely it will make this package more good.

@TheTechsTech
Copy link

It will be hard for him to produce the examples. What seems to be missing is the fact, this package as laid out is not standalone.

When this package calls ->wait() what else in your code base is allowed to run?
The whole constructs here need some other event loop like process to check the actual process status, then let other things run. His link in explaining/comparing to other completing packages, does just that.

As commented #98 the async\await as used is misplaced here.
It might be best for this package to finish up on #4 (comment).

Anyway, I extracted and reworked various parts of this package into a bigger package. The heart symplely/processor is the wrapper API for symfony/process, forked and renamed from PR.

What is Async? see https://symplely.github.io/coroutine/

For examples see https://github.com/symplely/coroutine/tree/master/examples,

@spatie spatie locked as off-topic and limited conversation to collaborators Feb 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants