Skip to content

Deadline execution#3146

Merged
Jumhyn merged 10 commits intoswiftlang:mainfrom
phausler:pr/deadline
Apr 7, 2026
Merged

Deadline execution#3146
Jumhyn merged 10 commits intoswiftlang:mainfrom
phausler:pr/deadline

Conversation

@phausler
Copy link
Copy Markdown
Contributor

This initially started off as a proposal for swift-async-algorithms, however it became very clear that it was a larger audience for potential usage and was decided that it would be better served as an addition to the Concurrency library.

This proposes adding a withDeadline function to the Concurrency library that allows execution of an asynchronous operation with a composable time limit.

to communicate a deadline to some other system it can use these properties to relay that information
without needing the deadline to be directly passed.

#### Behaviors for Cancellation and Expiration
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am still working on this section with detailed behavior examples

Comment thread proposals/NNNN-deadline.md Outdated

//// TODO

#### Interaction with Executors
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will update this once the discussions are finished around what this exactly is and needs to be.

@phausler phausler marked this pull request as draft February 25, 2026 18:39
@phausler phausler requested review from FranzBusch and ktoso February 25, 2026 18:39
@rjmccall rjmccall added LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document labels Mar 2, 2026
@rjmccall rjmccall mentioned this pull request Mar 9, 2026
Comment thread proposals/NNNN-deadline.md Outdated
to communicate a deadline to some other system it can use these properties to relay that information
without needing the deadline to be directly passed.

### Implementation Details
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.

Let's not share implementation details in the proposal, we may want to do some efficiency improvements for happy path etc. Including implementation in proposal would potentially tie us down to some unintended bits

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree with @ktoso that this level of specificity likely too detailed, but the "behavioral note" part about the cancel-but-wait behavior probably worth emphasizing!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that revealing the implementation details is fine here but I agree that it should claim that implementation is exchangeable with a more streamlined version that interoperates with executors (referenced later in the document under the future directions). Revealing the details gives the reader a point of reference to compare to existing behaviors.

/// - Throws: A ``DeadlineError`` indicating whether the operation failed before deadline
/// (``DeadlineError/Cause/operationFailed``) or was cancelled due to deadline expiration
/// (``DeadlineError/Cause/deadlineExceeded``).
nonisolated(nonsending) public func withDeadline<Return, Failure: Error>(
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.

nitpick, we put access control first in this combo of keywords:

Suggested change
nonisolated(nonsending) public func withDeadline<Return, Failure: Error>(
public nonisolated(nonsending) func withDeadline<Return, Failure: Error>(

public var cause: Cause

/// The deadline expiration that was specified for the operation.
public var expiration: any InstantProtocol
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to guard this out in embedded mode.

@Jumhyn Jumhyn marked this pull request as ready for review April 7, 2026 01:30
@Jumhyn Jumhyn merged commit a3f6c52 into swiftlang:main Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants