From fa5bbbb2bf3e1ea9c8fecbeebf25a2aee301eb24 Mon Sep 17 00:00:00 2001 From: Lukas Korba Date: Mon, 3 Oct 2022 20:54:43 +0200 Subject: [PATCH] [#541] Initialise gRPC on a separate thread (#545) MultiThreadedEventLoopGroup has been replaced with NIOTSEventLoopGroup. It's recommended by authors of grpc-swift especially for iOS platform and it allows us to set the priority because NIOTSEventLoopGroup is GCD based while MultiThreadedEventLoopGroup is pthread based. [#541] Initialise gRPC on a separate thread (#545) - priority increased to .default --- .../ZcashLightClientKit/Service/LightWalletGRPCService.swift | 5 +++-- Tests/TestUtils/Tests+Utils.swift | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/ZcashLightClientKit/Service/LightWalletGRPCService.swift b/Sources/ZcashLightClientKit/Service/LightWalletGRPCService.swift index b023a30d..3dbcfbbc 100644 --- a/Sources/ZcashLightClientKit/Service/LightWalletGRPCService.swift +++ b/Sources/ZcashLightClientKit/Service/LightWalletGRPCService.swift @@ -10,6 +10,7 @@ import Foundation import GRPC import NIO import NIOHPACK +import NIOTransportServices public typealias Channel = GRPC.GRPCChannel @@ -127,8 +128,8 @@ public class LightWalletGRPCService { self.singleCallTimeout = TimeLimit.timeout(.milliseconds(singleCallTimeout)) let connectionBuilder = secure ? - ClientConnection.usingPlatformAppropriateTLS(for: MultiThreadedEventLoopGroup(numberOfThreads: 1)) : - ClientConnection.insecure(group: MultiThreadedEventLoopGroup(numberOfThreads: 1)) + ClientConnection.usingPlatformAppropriateTLS(for: NIOTSEventLoopGroup(loopCount: 1, defaultQoS: .default)) : + ClientConnection.insecure(group: NIOTSEventLoopGroup(loopCount: 1, defaultQoS: .default)) let channel = connectionBuilder .withConnectivityStateDelegate(connectionManager, executingOn: queue) diff --git a/Tests/TestUtils/Tests+Utils.swift b/Tests/TestUtils/Tests+Utils.swift index 4d110bc1..d86f11e0 100644 --- a/Tests/TestUtils/Tests+Utils.swift +++ b/Tests/TestUtils/Tests+Utils.swift @@ -11,6 +11,7 @@ import GRPC import ZcashLightClientKit import XCTest import NIO +import NIOTransportServices enum Environment { static let lightwalletdKey = "LIGHTWALLETD_ADDRESS" @@ -40,8 +41,8 @@ class ChannelProvider { let endpoint = LightWalletEndpointBuilder.default let connectionBuilder = secure ? - ClientConnection.usingPlatformAppropriateTLS(for: MultiThreadedEventLoopGroup(numberOfThreads: 1)) : - ClientConnection.insecure(group: MultiThreadedEventLoopGroup(numberOfThreads: 1)) + ClientConnection.usingPlatformAppropriateTLS(for: NIOTSEventLoopGroup(loopCount: 1, defaultQoS: .default)) : + ClientConnection.insecure(group: NIOTSEventLoopGroup(loopCount: 1, defaultQoS: .default)) let channel = connectionBuilder .withKeepalive(