Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
5e672320
Commit
5e672320
authored
9 years ago
by
Jorge Canizales
Browse files
Options
Downloads
Patches
Plain Diff
Make Writeable with single handler robust against stream Writers
parent
232b6a8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/objective-c/RxLibrary/GRXWriteable.m
+32
-5
32 additions, 5 deletions
src/objective-c/RxLibrary/GRXWriteable.m
with
32 additions
and
5 deletions
src/objective-c/RxLibrary/GRXWriteable.m
+
32
−
5
View file @
5e672320
...
...
@@ -42,11 +42,38 @@
if
(
!
handler
)
{
return
[[
self
alloc
]
init
];
}
return
[[
self
alloc
]
initWithValueHandler
:
^
(
id
value
)
{
handler
(
value
,
nil
);
}
completionHandler
:
^
(
NSError
*
errorOrNil
)
{
if
(
errorOrNil
)
{
handler
(
nil
,
errorOrNil
);
// We nilify this variable when the block is invoked, so that handler is only invoked once even if
// the writer tries to write multiple values.
__block
GRXEventHandler
eventHandler
=
^
(
BOOL
done
,
id
value
,
NSError
*
error
)
{
// Nillify eventHandler before invoking handler, in case the latter causes the former to be
// executed recursively. Because blocks can be deallocated even during execution, we have to
// first retain handler locally to guarantee it's valid.
// TODO(jcanizales): Just turn this craziness into a simple subclass of GRXWriteable.
GRXSingleHandler
singleHandler
=
handler
;
eventHandler
=
nil
;
if
(
value
)
{
singleHandler
(
value
,
nil
);
}
else
if
(
error
)
{
singleHandler
(
nil
,
error
);
}
else
{
NSDictionary
*
userInfo
=
@{
NSLocalizedDescriptionKey:
@"The writer finished without producing any value."
};
// Even though RxLibrary is independent of gRPC, the domain and code here are, for the moment,
// set to the values of kGRPCErrorDomain and GRPCErrorCodeInternal. This way, the error formed
// is the one user of gRPC would expect if the server failed to produce a response.
//
// TODO(jcanizales): Figure out a way to keep errors of RxLibrary generic without making users
// of gRPC take care of two different error domains and error code enums. A possibility is to
// add error handling to GRXWriters or GRXWriteables, and use them to translate errors between
// the two domains.
singleHandler
(
nil
,
[
NSError
errorWithDomain
:
@"io.grpc"
code
:
13
userInfo
:
userInfo
]);
}
};
return
[
self
writeableWithEventHandler
:
^
(
BOOL
done
,
id
value
,
NSError
*
error
)
{
if
(
eventHandler
)
{
eventHandler
(
done
,
value
,
error
);
}
}];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment