Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ jobs:
uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main
cs:
uses: innmind/github-workflows/.github/workflows/cs.yml@main
with:
php-version: '8.2'
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## [Unreleased]

### Changed

- Requires PHP `8.4`
- Requires `innmind/operating-system:~7.0`
- Requires `innmind/time:~1.0`
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
"issues": "http://github.com/innmind/async/issues"
},
"require": {
"php": "~8.2",
"innmind/operating-system": "~6.2",
"innmind/immutable": "~5.18",
"innmind/io": "^3.5.1",
"innmind/time-warp": "^4.1.1",
"innmind/signals": "^4.1.1"
"php": "~8.4",
"innmind/operating-system": "~7.0",
"innmind/immutable": "~6.0",
"innmind/io": "~4.0",
"innmind/time": "~1.0",
"innmind/signals": "~5.0"
},
"autoload": {
"psr-4": {
"Innmind\\Async\\": "src/"
}
},
"require-dev": {
"innmind/static-analysis": "^1.2.1",
"innmind/static-analysis": "~1.3",
"innmind/black-box": "~6.5",
"innmind/coding-standard": "~2.0"
}
Expand Down
56 changes: 30 additions & 26 deletions proofs/functional.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
Scheduler,
Task,
};
use Innmind\OperatingSystem\Factory;
use Innmind\OperatingSystem\{
Factory,
Config\Resilient,
};
use Innmind\Signals\Signal;
use Innmind\TimeContinuum\Period;
use Innmind\Time\Period;
use Innmind\Filesystem\Name;
use Innmind\Http\{
Request,
Expand Down Expand Up @@ -111,23 +114,23 @@ static function($assert) {
[false, 0] => $continuation
->schedule(Sequence::of(
static function($os) {
$os->process()->halt(Period::second(1))->unwrap();
$os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
},
static function($os) {
$os->process()->halt(Period::second(1))->unwrap();
$os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
},
static function($os) {
$os->process()->halt(Period::second(1))->unwrap();
$os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();
},
))
->carryWith(true),
[true, 0] => (static function($os, $continuation) {
// this halt is executed at the same time at the
// second one in each task
$os->process()->halt(Period::second(1))->unwrap();
$_ = $os->process()->halt(Period::second(1))->unwrap();

return $continuation;
})($os, $continuation),
Expand All @@ -154,7 +157,7 @@ static function($assert) {
->with(
static function($started, $os, $continuation) use ($assert, &$results) {
if ($started) {
$os
$_ = $os
->process()
->halt(Period::second(2))
->unwrap();
Expand All @@ -170,14 +173,14 @@ static function($os) use (&$results) {
// This task halts for 4 seconds because
// if less then it may sometime finish
// before the scope. (as 3-1 ~= 2s)
$os
$_ = $os
->process()
->halt(Period::second(4))
->unwrap();
$results[] = 'task 1';
},
static function($os) use (&$results) {
$os
$_ = $os
->process()
->halt(Period::second(1))
->unwrap();
Expand Down Expand Up @@ -210,11 +213,11 @@ static function($assert) {
->with(
static function($started, $os, $continuation) use ($assert, &$results) {
if ($started) {
$os
$_ = $os
->process()
->halt(Period::second(3))
->unwrap();
$os
$_ = $os
->process()
->halt(Period::second(1))
->unwrap();
Expand All @@ -227,14 +230,14 @@ static function($started, $os, $continuation) use ($assert, &$results) {
->carryWith(true)
->schedule(Sequence::of(
static function($os) use (&$results) {
$os
$_ = $os
->process()
->halt(Period::second(2))
->unwrap();
$results[] = 'task 1';
},
static function($os) use (&$results) {
$os
$_ = $os
->process()
->halt(Period::second(1))
->unwrap();
Expand Down Expand Up @@ -404,17 +407,17 @@ static function($os) use ($assert, &$chunks) {
'HTTP requests are handled asynchronously',
static function($assert) {
$order = [];
Scheduler::of(Factory::build())
Scheduler::of(Factory::build()->map(Resilient::new()))
->sink(null)
->with(
static function($_, $__, $continuation) use ($assert, &$order) {
return $continuation
->schedule(Sequence::of(
static function($os) use ($assert, &$order) {
$os
$_ = $os
->remote()
->http()(Request::of(
Url::of('https://httpbun.org/delay/2'),
Url::of('https://httpbin.org/delay/5'),
Method::get,
ProtocolVersion::v11,
))
Expand All @@ -425,10 +428,10 @@ static function($os) use ($assert, &$order) {
$order[] = 'first';
},
static function($os) use ($assert, &$order) {
$os
$_ = $os
->remote()
->http()(Request::of(
Url::of('https://httpbun.org/delay/1'),
Url::of('https://httpbin.org/delay/1'),
Method::get,
ProtocolVersion::v11,
))
Expand Down Expand Up @@ -466,7 +469,7 @@ static function($assert) {
->wakeOnResult(),
);

$assert->count(0, $results);
$assert->same(0, $results->size());
},
);

Expand Down Expand Up @@ -522,18 +525,19 @@ static function($started, $os, $continuation) {
10,
static function($os) {
$continue = true;
$os
$_ = $os
->process()
->signals()
->listen(
Signal::terminate,
static function() use (&$continue) {
$continue = false;
},
);
)
->unwrap();

while ($continue) {
$os
$_ = $os
->process()
->halt(Period::second(2))
->unwrap();
Expand All @@ -542,7 +546,7 @@ static function() use (&$continue) {
));
}

$os
$_ = $os
->process()
->halt(Period::second(1))
->unwrap();
Expand Down
32 changes: 17 additions & 15 deletions src/Config/Async.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

use Innmind\OperatingSystem\Config;
use Innmind\Signals\Async\Interceptor;
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Period,
Halt,
};
use Innmind\HttpTransport\Curl;
use Innmind\TimeWarp\Halt;
use Innmind\HttpTransport\Transport;
use Innmind\IO\IO;
use Innmind\Signals\Handler;

/**
* @internal
Expand All @@ -29,22 +30,23 @@ private function __construct(

public function __invoke(Config $config): Config
{
$halt = Halt\Async::of($this->clock);
$io = IO::async($this->clock);
// todo handle max concurrency + ssl configuration
$halt = Halt::async($this->clock);
$io = IO::async(
$config->io(),
$this->clock,
);
// todo build a native client based on innmind/io to better integrate in
// this system.
$http = Curl::of(
$http = Transport::async(
$this->clock,
$io,
)
->heartbeat(
Period::millisecond(10), // this is blocking the active task so it needs to be low
static fn() => $halt(Period::millisecond(1))->unwrap(), // this allows to jump between tasks
);
$signals = $config
->signalsHandler()
->async($this->interceptor);
Period::millisecond(10), // this is blocking the active task so it needs to be low
static fn() => $halt(Period::millisecond(1))->unwrap(), // this allows to jump between tasks
);
$signals = Handler::async(
$config->signalsHandler(),
$this->interceptor,
);

return $config
->haltProcessVia($halt)
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Innmind\Async\Config;

use Innmind\Signals\Async\Interceptor;
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion src/Resumption.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Async;

use Innmind\TimeWarp\Async\Resumable as Halt;
use Innmind\Time\Halt\Async\Resumable as Halt;
use Innmind\IO\Internal\Async\Resumable as IO;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scope/Suspended.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Suspension,
Wait,
};
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

/**
* Waiting for IO to be ready or halt to be finished
Expand Down
4 changes: 2 additions & 2 deletions src/Suspension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace Innmind\Async;

use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Period,
Halt\Async\Suspended as Halt,
};
use Innmind\TimeWarp\Async\Suspended as Halt;
use Innmind\IO\Internal\{
Async\Suspended as IO,
Watch,
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Suspended.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Async\Interceptor,
Signal,
};
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

/**
* Waiting for IO to be ready or halt to be finished
Expand Down
2 changes: 1 addition & 1 deletion src/Wait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Innmind\Async;

use Innmind\OperatingSystem\OperatingSystem;
use Innmind\TimeContinuum\Period;
use Innmind\Time\Period;
use Innmind\IO\Internal\Watch;

/**
Expand Down