Skip to content

Commit 1785d23

Browse files
committed
Add error handler argument to send methods to better handle errors that occur when sending.
1 parent 2406b33 commit 1785d23

File tree

9 files changed

+72
-24
lines changed

9 files changed

+72
-24
lines changed

Examples/Echo/Generated/echo.client.pb.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class Echo_EchoGetCall {
6565
let sem = DispatchSemaphore(value: 0)
6666
var returnCallResult : CallResult!
6767
var returnResponse : Echo_EchoResponse?
68-
try start(request:request, metadata:metadata) {response, callResult in
68+
_ = try start(request:request, metadata:metadata) {response, callResult in
6969
returnResponse = response
7070
returnCallResult = callResult
7171
sem.signal()
@@ -176,9 +176,9 @@ public class Echo_EchoCollectCall {
176176
}
177177

178178
/// Call this to send each message in the request stream. Nonblocking.
179-
public func send(_ message: Echo_EchoRequest) throws {
179+
public func send(_ message:Echo_EchoRequest, errorHandler:@escaping (Error)->()) throws {
180180
let messageData = try message.serializeProtobuf()
181-
try call.sendMessage(data:messageData)
181+
try call.sendMessage(data:messageData, errorHandler:errorHandler)
182182
}
183183

184184
/// Call this to close the connection and wait for a response. Blocking.
@@ -274,9 +274,9 @@ public class Echo_EchoUpdateCall {
274274
}
275275

276276
/// Call this to send each message in the request stream.
277-
public func send(_ message:Echo_EchoRequest) throws {
277+
public func send(_ message:Echo_EchoRequest, errorHandler:@escaping (Error)->()) throws {
278278
let messageData = try message.serializeProtobuf()
279-
try call.sendMessage(data:messageData)
279+
try call.sendMessage(data:messageData, errorHandler:errorHandler)
280280
}
281281

282282
/// Call this to close the sending connection. Blocking.

Examples/Echo/Xcode/Echo.xcodeproj/project.pbxproj

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
D30625D01E61331600C92C6A /* BoringSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D363FEDF1E5F751500D8F135 /* BoringSSL.framework */; };
11+
D30625D11E61331600C92C6A /* CgRPC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D363FEE11E5F751500D8F135 /* CgRPC.framework */; };
12+
D30625D21E61331600C92C6A /* gRPC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D363FEE31E5F751500D8F135 /* gRPC.framework */; };
13+
D30625D31E61331D00C92C6A /* SwiftProtobuf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3F7791E1E380C140002CB64 /* SwiftProtobuf.framework */; };
1014
D35358201E219963007FA223 /* echo.client.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = D353581D1E219963007FA223 /* echo.client.pb.swift */; };
1115
D35358211E219963007FA223 /* echo.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = D353581E1E219963007FA223 /* echo.pb.swift */; };
1216
D35358221E219963007FA223 /* echo.server.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = D353581F1E219963007FA223 /* echo.server.pb.swift */; };
@@ -20,6 +24,27 @@
2024
/* End PBXBuildFile section */
2125

2226
/* Begin PBXContainerItemProxy section */
27+
D30625C31E6132AA00C92C6A /* PBXContainerItemProxy */ = {
28+
isa = PBXContainerItemProxy;
29+
containerPortal = D363FED71E5F751500D8F135 /* SwiftGRPC.xcodeproj */;
30+
proxyType = 1;
31+
remoteGlobalIDString = OBJ_782;
32+
remoteInfo = BoringSSL;
33+
};
34+
D30625C51E6132AA00C92C6A /* PBXContainerItemProxy */ = {
35+
isa = PBXContainerItemProxy;
36+
containerPortal = D363FED71E5F751500D8F135 /* SwiftGRPC.xcodeproj */;
37+
proxyType = 1;
38+
remoteGlobalIDString = OBJ_1086;
39+
remoteInfo = CgRPC;
40+
};
41+
D30625C71E6132AA00C92C6A /* PBXContainerItemProxy */ = {
42+
isa = PBXContainerItemProxy;
43+
containerPortal = D363FED71E5F751500D8F135 /* SwiftGRPC.xcodeproj */;
44+
proxyType = 1;
45+
remoteGlobalIDString = OBJ_1366;
46+
remoteInfo = gRPC;
47+
};
2348
D363FEDE1E5F751500D8F135 /* PBXContainerItemProxy */ = {
2449
isa = PBXContainerItemProxy;
2550
containerPortal = D363FED71E5F751500D8F135 /* SwiftGRPC.xcodeproj */;
@@ -107,6 +132,10 @@
107132
isa = PBXFrameworksBuildPhase;
108133
buildActionMask = 2147483647;
109134
files = (
135+
D30625D31E61331D00C92C6A /* SwiftProtobuf.framework in Frameworks */,
136+
D30625D01E61331600C92C6A /* BoringSSL.framework in Frameworks */,
137+
D30625D11E61331600C92C6A /* CgRPC.framework in Frameworks */,
138+
D30625D21E61331600C92C6A /* gRPC.framework in Frameworks */,
110139
);
111140
runOnlyForDeploymentPostprocessing = 0;
112141
};
@@ -193,6 +222,9 @@
193222
buildRules = (
194223
);
195224
dependencies = (
225+
D30625C41E6132AA00C92C6A /* PBXTargetDependency */,
226+
D30625C61E6132AA00C92C6A /* PBXTargetDependency */,
227+
D30625C81E6132AA00C92C6A /* PBXTargetDependency */,
196228
D3F779261E380C310002CB64 /* PBXTargetDependency */,
197229
D38E00371E315DB700CE7B16 /* PBXTargetDependency */,
198230
D38E00391E315DB700CE7B16 /* PBXTargetDependency */,
@@ -338,6 +370,21 @@
338370
/* End PBXSourcesBuildPhase section */
339371

340372
/* Begin PBXTargetDependency section */
373+
D30625C41E6132AA00C92C6A /* PBXTargetDependency */ = {
374+
isa = PBXTargetDependency;
375+
name = BoringSSL;
376+
targetProxy = D30625C31E6132AA00C92C6A /* PBXContainerItemProxy */;
377+
};
378+
D30625C61E6132AA00C92C6A /* PBXTargetDependency */ = {
379+
isa = PBXTargetDependency;
380+
name = CgRPC;
381+
targetProxy = D30625C51E6132AA00C92C6A /* PBXContainerItemProxy */;
382+
};
383+
D30625C81E6132AA00C92C6A /* PBXTargetDependency */ = {
384+
isa = PBXTargetDependency;
385+
name = gRPC;
386+
targetProxy = D30625C71E6132AA00C92C6A /* PBXContainerItemProxy */;
387+
};
341388
D38E00371E315DB700CE7B16 /* PBXTargetDependency */ = {
342389
isa = PBXTargetDependency;
343390
name = BoringSSL;

Examples/Echo/Xcode/Echo/EchoViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ class EchoViewController : NSViewController, NSTextFieldDelegate {
232232
if let collectCall = collectCall {
233233
let requestMessage = Echo_EchoRequest(text:self.messageField.stringValue)
234234
self.displayMessageSent(requestMessage.text)
235-
try collectCall.send(requestMessage)
235+
try collectCall.send(requestMessage) {error in print(error)}
236236
}
237237
}
238238

239239
func sendUpdateMessage() throws {
240240
if let updateCall = updateCall {
241241
let requestMessage = Echo_EchoRequest(text:self.messageField.stringValue)
242242
self.displayMessageSent(requestMessage.text)
243-
try updateCall.send(requestMessage)
243+
try updateCall.send(requestMessage) {error in print(error)}
244244
}
245245
}
246246

0 commit comments

Comments
 (0)