Skip to content

Conversation

@rconnell9
Copy link
Contributor

Ensure call to unsafe_await is not called from Swifts concurrency system

Motivation:

Defensive check in response to:
#9441

Modifications:

Ensure call to unsafe_await is not called from Swift's concurrency system (an asynchronous context).

@rconnell9
Copy link
Contributor Author

@swift-ci test

public func unsafe_await<T: Sendable>(_ body: @Sendable @escaping () async -> T) -> T {
withUnsafeCurrentTask { task in
if task != nil {
fatalError("This function must not be invoked from the Swift Concurrency thread pool.")
Copy link
Contributor

Choose a reason for hiding this comment

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

question: will the fatal error contains the function reference? if not, consider replading function with \(#function) and maybe even include \(#file) somewhere in the message .

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call, but only if passing in #function as a default parameter argument, otherwise it will be constant, which isn't that useful.

I think backtraces give you most of the value anyways.

@rconnell9
Copy link
Contributor Author

@swift-ci test

1 similar comment
@rconnell9
Copy link
Contributor Author

@swift-ci test

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.

3 participants