-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Promise timer wont stop sub-processes #65
Comments
You have to new Promise(function (callable $resolve) {
echo "Task Start" . PHP_EOL;
$resolve(
\React\Promise\Timer\sleep(10)
->then(function () {
echo "Sleep Complete and Run" . PHP_EOL;
})
);
}); and the output should be like below if you use promises correctly:
|
Got it @hasanparasteh ! Thanks |
I had some workarounds and the issue still exist although I'm using here is an example: timeout(new Promise(function (callable $resolve) {
echo "Task Start" . PHP_EOL;
$resolve(\React\Promise\Timer\sleep(4)
->then(function () {
echo "First Sleep Run" . PHP_EOL;
// It Must Be Canceled Here But it run
return \React\Promise\Timer\sleep(5)
->then(function () {
echo "Second Sleep Run" . PHP_EOL;
});
}));
}), 5)->then(function ($result) {
echo "Task Resolved Success" . PHP_EOL;
}, function (\Exception $exception) {
echo "Task Timeout" . PHP_EOL;
}); |
Looks like you're locking a canceler to pass on the timeout canceling the initial promise: $p = null;
timeout(new Promise(function (callable $resolve) use (&$p) {
echo "Task Start" . PHP_EOL;
$resolve($p = \React\Promise\Timer\sleep(4)
->then(function () {
echo "First Sleep Run" . PHP_EOL;
// It Must Be Canceled Here But it run
return \React\Promise\Timer\sleep(5)
->then(function () {
echo "Second Sleep Run" . PHP_EOL;
});
}));
}, function () use (&$p) {
$p->cancel();
}, 5)->then(function ($result) {
echo "Task Resolved Success" . PHP_EOL;
}, function (\Exception $exception) {
echo "Task Timeout" . PHP_EOL;
}); |
It should cancel it, wrote that code without running it because that should be enough. Having a deeper dive |
@Parsoolak Can you tell us a bit more what you're trying to achieve, understanding your use case helps us to guide you in the right direction. It's hard to make out what's actually happening in your example, did you take a look at the promise documentation? |
@SimonFrings Technically @Parsoolak has a very good point as that I would also expect that to work. (This one specifically #65 (comment) .) However when using that |
@WyriHaximus Maybe it makes more sense to try another approach to reach a result, instead of trying to fix the code example above. Promises, especially with cancellation, can be tricky from time to time and is not perfect, there's also been quite a discussion about this in reactphp/promise#56. I'd suggest to try out https://github.com/reactphp/async, using the All in all it seems to me this ticket isn't about a problem in https://github.com/reactphp/promise-timer, but more suited for https://github.com/reactphp/promise. What do you guys think? |
I agree. lets move over https://github.com/reactphp/promise and talk more about this issue. |
Hi dear @clue ,
I Think I found a bug!
or I am just confused how this promise-timer works!
When I below Code, My Base Promise Canceled But Sub-processes wont stop and continue their works
and Code Response:
Why it act like that and wont stop sub-processes?
whats wrong in my Ideology؟
The text was updated successfully, but these errors were encountered: