Skip to content

feat(#92): add Future::awaitAll/onReady and range read-ahead - #109

Closed
s2x wants to merge 1 commit into
masterfrom
feat/92-await-all-and-range-read-ahead
Closed

feat(#92): add Future::awaitAll/onReady and range read-ahead#109
s2x wants to merge 1 commit into
masterfrom
feat/92-await-all-and-range-read-ahead

Conversation

@s2x

@s2x s2x commented Sep 9, 2026

Copy link
Copy Markdown
Member

Closes #92

Implements the first, self-contained slice of #92 (per the issue's own note that read-ahead + group await deliver most of the practical win without the callback binding):

Added

  • Future::awaitAll(array $futures): array — resolves a batch of futures that were all issued up front. Since every future is already in flight, awaiting them in order costs roughly one round trip of total latency, not N.
  • Future::onReady(callable $fn): void — PHP-thread completion hook (runs immediately for a ready future, otherwise blocks then invokes).
  • Deliberately NOT bound: fdb_future_set_callback — its callback fires on the FDB network thread, where executing PHP is unsafe (same reasoning as the existing NativeClient::onNetworkThreadCompletion). Documented in docs/advanced.md.

Changed

  • RangeResult::paginate() now issues the request for the next chunk before yielding any item of the current chunk (read-ahead, mirroring Java's AsyncIterable). Read-ahead never fetches past an explicit limit; iteration order, dedup guarantees and pagination semantics are unchanged.
  • New KvResultFuture interface (implemented by FutureKeyValueArray) describes the pagination contract and keeps paginate() unit-testable without a cluster.

Tests

  • tests/Unit/FutureAwaitAllTest.php — stub-lib unit tests for awaitAll() / onReady() (ready & not-ready paths, empty batch, non-Future rejection).
  • tests/Unit/RangeResultTest.php — new tests proving the next-chunk request is issued before the first item of the current chunk is consumed, and that no page beyond the limit is requested.
  • tests/Integration/FutureAwaitAllIntegrationTest.php — live-cluster coverage: 50 parallel reads resolved via awaitAll(), mixed future types resolved in order.

Docs & changelog

CI: composer lint (PHPCS + Rector dry-run + PHPStan level 9) and composer test (unit + integration against a 5-node Docker FDB cluster) are clean locally.

Remaining from #92 (not in this PR): Fiber-aware await and any eventual safe callback binding — these stay as follow-up work on the issue.

- Future::awaitAll() resolves N futures issued up front with ~1 round trip
  of total latency; Future::onReady() registers a PHP-thread completion hook
- fdb_future_set_callback stays deliberately unbound (callbacks fire on the
  FDB network thread where PHP is unsafe)
- RangeResult::paginate() now issues the next chunk request before yielding
  the current chunk (read-ahead), without ever fetching past an explicit
  limit; new KvResultFuture contract keeps pagination testable
- docs/advanced.md: 'Group Awaits and Completion Hooks' section
- unit tests (stub lib) + integration tests against a live cluster
@s2x

s2x commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Closing as superseded by #111 — the same functionality (Future::awaitAll()/onReady(), RangeResult read-ahead, KvResultFuture, unit/integration tests, docs and CHANGELOG entries) was already squash-merged to master in commit df4e86e. No additional commits on this branch; nothing here is lost. Remaining follow-ups from #92 stay on the issue.

@s2x s2x closed this Sep 9, 2026
@s2x
s2x deleted the feat/92-await-all-and-range-read-ahead branch September 9, 2026 11:20
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.

Add non-blocking future support (fdb_future_set_callback, awaitAll, range read-ahead)

1 participant