jcavar
(Josip Cavar)
1
The following example doesn't generate any concurrency warnings in Swift 5.10:
@MainActor
public final class Test {
func process() {
}
}
public extension Test {
func start() {
let browser = NWBrowser(
for: .bonjour(type: MIDINetworkBonjourServiceType, domain: nil),
using: NWParameters()
)
browser.browseResultsChangedHandler = { [weak self] newResult, changes in
Task { [weak self] in
self?.process() // no warning, compiles ok
}
}
}
}
If I move start out of extension, then I get a warning as I would expect.
Is this a bug, or am I missing something here?
eskimo
(Quinn “The Eskimo!”)
2
The following example doesn't generate any concurrency
warnings in Swift 5.10:
It does if you set Strict Concurrency Checking to Complete:
browser.browseResultsChangedHandler = { [weak self] newResult, changes in
Task { [weak self] in
self?.process() // no warning, compiles ok
// ^ Expression is 'async' but is not marked with 'await'
}
}
IME there’s not much point in trying to reason about Swift concurrency without enabling strict checking.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
1 Like