Skip to content

Commit

Permalink
Update to version 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Oct 25, 2024
1 parent be2e08b commit 6afe8e5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudtay/ripple",
"version": "v0.6.2",
"version": "v0.8.1",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
use Closure;
use Co\Coroutine;
use Co\System;
use Ripple\Coroutine\Promise;
use Ripple\Coroutine\Suspension;
use Revolt\EventLoop;
use Revolt\EventLoop\UnsupportedFeatureException;
use Ripple\Coroutine\Promise;
use Ripple\Coroutine\Suspension;
use Symfony\Component\DependencyInjection\Container;
use Throwable;
use Fiber;

use function call_user_func;
use function Co\async;
Expand Down Expand Up @@ -244,7 +245,6 @@ public function cancelForked(string $index): void
* @param Closure|null $result
*
* @return bool
* @throws Throwable
*/
public function wait(Closure|null $result = null): bool
{
Expand All @@ -255,6 +255,7 @@ public function wait(Closure|null $result = null): bool
if (!$this->mainRunning) {
try {
\Ripple\Coroutine\Coroutine::resume($this->mainSuspension, $result);
Fiber::suspend();
} catch (Throwable) {
exit(1);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,8 @@ public function task(Closure $closure): Task|false
// Whether it belongs to the ripple coroutine space
// forked and user actions need to be deferred because they clear the coroutine hash table
// If you don't do this, fiber escape will occur

EventLoop::defer(function () use ($closure, $args) {
$this->forkedTick();
call_user_func($closure, ...$args);
});

$this->forkedTick();
call_user_func($closure, ...$args);
throw new EscapeException('The process is abnormal.');
}

Expand Down
4 changes: 1 addition & 3 deletions tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function test_coroutine(): void
$async = async(function () use ($code) {
$task = System::Process()->task(function () use ($code) {
\Co\sleep(1);
defer(function () use ($code) {
exit($code);
});
exit($code);
});
$runtime = $task->run();
return await($runtime->getPromise());
Expand Down

0 comments on commit 6afe8e5

Please sign in to comment.