bagart/ask-client

Async network client and HTTP transport layer for the ASK runtime

Maintainers

Package info

github.com/bagart/php-async-kernel-client

pkg:composer/bagart/ask-client

Transparency log

Statistics

Installs: 0

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-22 08:46 UTC

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 / finally chain

  • ASKContext — immutable context with with() / without() / merge()

  • ASKTransportwrap(callable) / null() / execute()

  • ASKNextHandler — typed next-handler replacing callable

  • Contracts* — interfaces for all core components