Skip to content

Commit e83b0a2

Browse files
committed
Deprecate runAsyncAndBlock API
We don't want people using this as a means of jumping from synchronous code to async code. It blocks the thread that it's running on and spawns a new thread to run the async code. This has a couple of drawbacks. First, if it blocks a thread that is needed by the async code (i.e, calling something on the main actor while blocking the main thread), it is an immediate deadlock. This is a bad day for everyone. Second, it can easily lead to thread-explosions. The proper entry-point for async code is to use something of the following form: ``` @main struct Main { static func main() async { // ... } } ``` This should take care of most new code. There are still places where folks will need to jump from synchronous code to async code. That still needs to be designed and implemented, but we don't want people to come to rely on `runAsyncAndBlock`.
1 parent 5b11a4a commit e83b0a2

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func _enqueueJobGlobal(_ task: Builtin.Job)
323323
@_silgen_name("swift_task_isCancelled")
324324
func isTaskCancelled(_ task: Builtin.NativeObject) -> Bool
325325

326+
@available(*, deprecated)
326327
@_silgen_name("swift_task_runAndBlockThread")
327328
public func runAsyncAndBlock(_ asyncFun: @escaping () async -> ())
328329

0 commit comments

Comments
 (0)