-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New materialize() operator over BlockingObservable
#1383
New materialize() operator over BlockingObservable
#1383
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, I just have one comment over naming that I'd like to discuss, and also I think it would be really nice to add a quick section on using this operator here: https://github.com/ReactiveX/RxSwift/blob/master/Documentation/UnitTests.md#integration-tests
@@ -10,14 +10,20 @@ | |||
import RxSwift | |||
#endif | |||
|
|||
public enum SequenceMaterializeResult<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure on the naming here,
Would expect MaterializedSequenceResult<T>
perhaps
Also wondering if it could be nice to go with elements
and errors
similar to RxSwiftExt's operators that extend materialize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rename totally make sense, I'll do that. In terms of errors
do you mean in the enum case name or in the associated value parameter?
I'm not sure plural errors
makes sense given it's only a single error that terminates the sequence? (I think, Rx newbie here).
- In case name:
public enum MaterializedSequenceResult<T> {
case completed(elements: [T])
case errors(elements: [T], error: Error)
}
- In associated value name
public enum MaterializedSequenceResult<T> {
case completed(elements: [T])
case failed(elements: [T], errors: [Error])
}
Good point, examples added to UnitTests.md documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up the documentation a bit, and after thinking this over night yesterday - .completed
and .failed
make sense to me. Even though there is a disparity between what materialize()
returns in RxSwift vs RxBlocking, I think that should be fine mostly.
I think this PR is all good to go on my end. Let's wait for @kzaher to review this and merge :)
BlockingObservable
@sgleadow Could you also real quickly add a CHANGELOG entry with something along the lines of "Added |
Thanks for the help. I had no idea you could push to my fork! I've added a line to the CHANGELOG referencing this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found some smaller items, but in general looks good.
Documentation/UnitTests.md
Outdated
|
||
switch result { | ||
case .completed: | ||
XCTFail("Expected result to be complete eith error, but result was successful.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eith
-> with
?
@@ -10,14 +10,20 @@ | |||
import RxSwift | |||
#endif | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should document this, what completed
means, what failed
means and what is this enum
for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually added this in the documentation: https://github.com/ReactiveX/RxSwift/pull/1383/files/d416ff5e5c4f461c8afe262824f7d34f73d06e81#diff-6eb6c44aac5cc628cd1c254752e52e36R101
Did you want to see something besides that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or your mean inline documentation block for that enum ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tweaked the UnitTests.md
and added an example of the successful case, not just the error case.
Although if you mean inline docs like @freak4pc mentioned, I can add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through other parts of the RxSwift codebase and thought an inline comment describing the MaterializedSequenceResult
was also appropriate, so I've added that also.
/// If the sequence terminates successfully, the result is represented | ||
/// by `.completed` with the array of elements. | ||
/// | ||
/// If the sequene terminates with error, the result is represented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo sequene
|
||
switch result { | ||
case .completed: | ||
XCTFail("Expected result to be complete eith error, but result was successful.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo eith
.
This is based on a discussion in #1355 and on previous changes in #1354.
We introduce new extension to
BlockingObservable
calledmaterialize()
which returns a result type capturing the completed/failed status of the sequence, along with and elements and the error. The result type looks like this:Internally, the rest of the
BlockingObservable+Operators
useSequenceMaterializeResult
, and onlythrow
at the last minute if an unexpected error occurs. This is mostly to maintain a backwards compatible interface for the existing operators, so it's a non-breaking change.