Skip to content

Add Future completion subscriptions - #1

Closed
simPod wants to merge 1 commit into
3.xfrom
feat/future-subscribe
Closed

Add Future completion subscriptions#1
simPod wants to merge 1 commit into
3.xfrom
feat/future-subscribe

Conversation

@simPod

@simPod simPod commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Context

Promise adapters may need to observe a Future completion without transforming it into another Future.

Decision

Add Future::subscribe() and Future::unsubscribe() as public facades for the existing one-shot completion callback mechanism.

Consequences

Adapters can observe values and errors without allocating derived Future chains. Callback subscriptions can be removed before a Future completes.

Benchmark Context

A wide asynchronous result graph with 838 parent objects and three Future-backed fields measured the cost of moving from Fiber-per-continuation handling to direct callback composition:

Adapter strategy CPU time Peak memory
Fiber per continuation 2.11 s 274 MB
Direct callback composition 1.67-1.70 s 149 MB

That workload reduced CPU time by about 19% and peak memory by about 46%. These measurements provide motivation for a public completion subscription API; they are not a general performance guarantee.

@simPod

simPod commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR amphp#469.

@simPod simPod closed this Aug 18, 2026
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