Skip to content
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

cancelled flow() to reject with new FlowCancellationError #2172

Merged
merged 5 commits into from
Nov 7, 2019
Merged

cancelled flow() to reject with new FlowCancellationError #2172

merged 5 commits into from
Nov 7, 2019

Conversation

vonovak
Copy link
Contributor

@vonovak vonovak commented Oct 21, 2019

This exports new FlowCancellationError and isFlowCancellationError helper because it's a little unusual to have to rely on FLOW_CANCELLED in our code base instead of importing this from mobx.

Copy link
Contributor

@danielkcz danielkcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, given it's just a string, it doesn't seem to be that big deal. It's a weird method of detecting cancel anyway. It might be better to have a custom FlowCancelError instance that can be checked instead.

@vonovak
Copy link
Contributor Author

vonovak commented Oct 21, 2019

@FredyC yes, it's mostly a stylistic issue. I'd be in favor of having a custom error for this, if you guys prefer - it's just a little more invasive but shouldn't be breaking (if we keep the same message) afaict.

@danielkcz
Copy link
Contributor

danielkcz commented Oct 21, 2019

it's just a little more invasive but shouldn't be breaking (if we keep the same message) afaict.

That's exactly my line of thinking :) Perhaps even expose something like isFlowCancelError which checks for the error instance. Can you do it, please?

Also, we will need this in mobx4-master branch and update the changelog (only in master).

@vonovak
Copy link
Contributor Author

vonovak commented Oct 22, 2019

@FredyC ok, so I added FlowCancellationError and also isFlowCancellationError(error). Frankly, I'm not sure if such simple function is worth increasing the api surface fo the library, but I'll leave that up to you guys. I can easily revert it.

Also, we will need this in mobx4-master branch and update the changelog (only in master).

crap, forgot about that. So the same changes (just code, not docs) but for different branch?

@danielkcz
Copy link
Contributor

ok, so I added FlowCancellationError and also isFlowCancellationError(error). Frankly, I'm not sure if such simple function is worth increasing the api surface fo the library, but I'll leave that up to you guys. I can easily revert it.

Thanks, I think it's ok. Not exactly the API surface increase, just a cleaner way of handling an existing feature.

crap, forgot about that. So the same changes (just code, not docs) but for different branch?

I am not sure if Flow is handled differently in MobX4, but chances are it's possible to just cherry pick those commits there and won't need much of the changes.

@vonovak vonovak changed the title export FLOW_CANCELLED constant add FlowCancellationError Oct 22, 2019
@vonovak vonovak changed the title add FlowCancellationError cancelled flow() to reject with new FlowCancellationError Oct 23, 2019
@mweststrate
Copy link
Member

I think this is a neat approach indeed. Let's make it part of the next minor

@danielkcz
Copy link
Contributor

Still waiting for MobX4 version, @vonovak will you be able to prepare that?

@vonovak
Copy link
Contributor Author

vonovak commented Nov 7, 2019

@FredyC I'll open a new PR for mobx4 in a few hours.

@vonovak
Copy link
Contributor Author

vonovak commented Nov 7, 2019

@FredyC please see #2190 - please note I had to change the implementation from this

export class FlowCancellationError extends Error {
    constructor() {
        super("FLOW_CANCELLED")
    }
}

to this

export function FlowCancellationError() {
    this.message = "FLOW_CANCELLED"
}
FlowCancellationError.prototype = Object.create(Error.prototype)

as otherwise the tests were failing. Please let me know if you want to use the second impl for this PR too.

@danielkcz danielkcz merged commit e5a2170 into mobxjs:master Nov 7, 2019
@danielkcz
Copy link
Contributor

Thanks!

@vonovak vonovak deleted the exportFlowCancelled branch November 7, 2019 17:20
@mweststrate
Copy link
Member

Published as 5.15.0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants