Skip to content

feat: add amphp/amp v3 fiber-based promise adapter - #4

Open
simPod wants to merge 7 commits into
masterfrom
fibers
Open

feat: add amphp/amp v3 fiber-based promise adapter#4
simPod wants to merge 7 commits into
masterfrom
fibers

Conversation

@simPod

@simPod simPod commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds Overblog\PromiseAdapter\Adapter\AmpFutureAdapter, a promise adapter backed by amphp/amp v3 fiber-based Amp\Futures.
  • Makes the DataLoader core fiber-aware so batching works under amp v3: dispatchQueueBatch() fans out via Amp\async + Future::await(), static await() delegates Amp\Futures to the adapter, and load() schedules batch dispatch on the next event-loop tick via Revolt\EventLoop::queue() (mirroring the JS reference process.nextTick).
  • Extracts the batch fan-out into resolveDispatchedBatch() shared by both the then() and fiber paths.

Why

amp v3 Futures expose no then() and only settle once the event loop advances, so the existing then()-based DataLoader core could not be driven by them. This unblocks running the webonyx AmpFutureAdapter executor (amp v3) together with DataLoader batching.

Validation

Proof-of-concept against webonyx GraphQL::promiseToExecute with AmpFutureAdapter, executed inside a root fiber:

  • 3 fields resolving via DataLoader::load()1 batchLoadFn call (batching confirmed).
  • Per-key failure surfaces as a field error at the correct path while sibling fields resolve.

Impact

  • Existing adapters (Guzzle / ReactPHP / Webonyx sync) are untouched — all fiber branches are guarded by instanceof.
  • amphp/amp is a dev/suggested dependency only.

Note: targeted at cdn77 (the branch consumed downstream). The change is adapter-additive and equally applies to master; happy to retarget/upstream.

Add a fiber-based AmpFutureAdapter and update DataLoader to dispatch, await, and resolve amphp/amp v3 futures. Preserve keyed and positional batch result handling, propagate throwables, and keep synchronous adapters unchanged.
@simPod
simPod changed the base branch from cdn77 to master August 19, 2026 07:40
simPod added 6 commits August 19, 2026 09:45
Context: Amp futures require event-loop scheduling, explicit observation, and synchronous cancellation handling.

Decision: add an optional async adapter interface and keep Amp scheduling, draining, observation, and cancellation inside the adapter.

Consequences: DataLoader remains promise-library agnostic, and nested or concurrent waits settle without deadlocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant