Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/Basics/Concurrency/ConcurrencyHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public enum Concurrency {

@available(*, noasync, message: "This method blocks the current thread indefinitely. Calling it from the concurrency pool can cause deadlocks")
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.

}
}

let semaphore = DispatchSemaphore(value: 0)

let box = ThreadSafeBox<T>()
Expand Down
Loading