bagart / ask-client
Async network client and HTTP transport layer for the ASK runtime
dev-main
2026-07-22 08:46 UTC
Requires
- php: >=8.2
- bagart/async-kernel: *
- psr/http-message: ^1.0|^2.0
Requires (Dev)
- amphp/dns: ^2.4
- amphp/http-client: ^5.0
- guzzlehttp/guzzle: ^7.0
- guzzlehttp/psr7: ^2.0
- react/dns: ^1.13
This package is not auto-updated.
Last update: 2026-07-23 16:53:16 UTC
README
Minimal deterministic execution engine: execute(object $operation): ASKFuture
Usage
use BAGArt\ASKClient\ASKClient; use BAGArt\ASKClient\ASKTransport; use BAGArt\ASKClient\ASKContext; use BAGArt\ASKClient\ASKFuture; $client = new ASKClient( transport: ASKTransport::wrap(fn (object $op, ASKContext $ctx): ASKFuture => ASKFuture::resolved($result), ), ); $result = $client->execute($operation)->await();
Future chain
$result = $client ->execute($operation) ->then(fn ($x) => $x + 1) ->then(fn ($x) => $x * 2) ->await(); $recovered = $client ->execute($operation) ->recover(fn (Throwable $e) => []) ->await();
Client with handlers
$client = new ASKClient( transport: $transport, handlers: [new MyRetryHandler(), new MyLoggingHandler()], );
Handler contract
A handler is a single unified type (no separate middleware/stage layers):
$handler = new class () implements ASKHandlerContract { public function __invoke( object $operation, ASKContextContract $context, ASKNextHandler $next, ): ASKFutureContract { return $next($operation, $context); } };
Architecture
execute(operation)
↓
handler chain
↓
transport
↓
future
-
ASKClient — entry point,
::create(...$handlers)factory -
ASKFuture — lazy future with
then/catch/recover/finallychain -
ASKContext — immutable context with
with()/without()/merge() -
ASKTransport —
wrap(callable)/null()/execute() -
ASKNextHandler — typed next-handler replacing
callable -
Contracts* — interfaces for all core components