Skip to content

Document EventLoopFuture callback lifetimes - #3701

Open
Hashim1999164 wants to merge 1 commit into
apple:mainfrom
Hashim1999164:document-future-callback-lifetimes
Open

Document EventLoopFuture callback lifetimes#3701
Hashim1999164 wants to merge 1 commit into
apple:mainfrom
Hashim1999164:document-future-callback-lifetimes

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Aug 13, 2026

Copy link
Copy Markdown

Summary

Developers coming from UIKit often capture self weakly in Future callbacks to avoid retain cycles. EventLoopFuture callbacks run at most once and are then dropped. Dropping an EventLoopPromise without completing it is programmer error. Together those rules mean a strong capture of self is the correct default.

This adds a Callback lifetimes section to the EventLoopFuture type docs and notes the completion requirement on EventLoopPromise.

Fixes #1575

Test plan

This change is documentation only. I reviewed the new section against the existing Callbacks threading notes on EventLoopFuture.

Motivation:

Developers coming from UIKit often capture self weakly in Future
callbacks to avoid retain cycles. For EventLoopFuture that pattern is
unnecessary: callbacks run at most once and are then dropped, and
dropping an EventLoopPromise without completing it is programmer error.

Modifications:

Add a Callback lifetimes section to the EventLoopFuture type docs, and
note on EventLoopPromise that completing a promise is required.

Result:

The docs discourage weak and unowned captures in Future callbacks and
explain why a strong capture of self is the correct default.

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you!

@Lukasa Lukasa added the semver/none No version bump required. label Aug 13, 2026
@Lukasa
Lukasa enabled auto-merge (squash) August 13, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document patterns around weak/unowned capture in futures

2 participants