Skip to content

Commit 39c91a8

Browse files
authored
NetworkPreference.best should be POSIX on older platforms (#896)
Motivation: While NetworkPreference.best was supposed to abstract away the choice of exactly which event loop would be used, on older Darwin platforms it would actually lead to runtime crashes as it would try to use an implementation it didn't have. Modifications: Have .best's .implementation fall back to POSIX on older platforms. Result: Fewer crashes on older platforms.
1 parent 183e380 commit 39c91a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/GRPC/PlatformSupport.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ extension NetworkPreference {
7878
switch self.wrapped {
7979
case .best:
8080
#if canImport(Network)
81-
guard #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) else {
82-
// This is gated by the availability of `.networkFramework` so should never happen.
83-
fatalError(".networkFramework is being used on an unsupported platform")
81+
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
82+
return .networkFramework
83+
} else {
84+
// Older platforms must use the POSIX loop.
85+
return .posix
8486
}
85-
return .networkFramework
8687
#else
8788
return .posix
8889
#endif

0 commit comments

Comments
 (0)