-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adding CancellationBag #345
Conversation
This is of course an incremental non breaking change. |
@hfossli Thank you for this! I think your solution is much more ergonomic and developer-friendly than the In my case I was hitting this issue (e.g.
So far using your approach in this PR has fixed the crashes that I was seeing related to that workflow, and I like that the |
} | ||
} | ||
} | ||
|
||
var cancellationCancellables: [AnyHashable: Set<AnyCancellable>] = [:] | ||
let cancellablesLock = NSRecursiveLock() | ||
fileprivate struct Lock { |
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.
TCA already provides an extension on NSRecursiveLock for sync located in Internal/Locking.swift
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.
Yup, just wanted a simple standalone file that could be copied out and in to any project
@hfossli I think it's possible to extend Reducer with a method (that calls |
Interesting! I'm all ears. Do you have some example? I couldn't find any simple solutions. |
return subject.handleEvents( | ||
receiveCompletion: { _ in cancellationCancellable.cancel() }, | ||
receiveCancel: cancellationCancellable.cancel | ||
) | ||
} | ||
.eraseToEffect() | ||
|
||
return cancelInFlight ? .concatenate(.cancel(id: id), effect) : effect |
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.
Shouldn't this be:
return cancelInFlight ? .concatenate(.cancel(id: id, bag: bag), effect) : effect
@hfossli I'm going to close this out in tandem with #335 (comment) Thanks again! |
As per discussion on https://forums.swift.org/t/how-can-the-composable-architecture-really-become-composable/43045/2
This can be instead or in addition to #335
Let me know if you approve of this direction and I'll spend time writing unit tests and documentation. ☀️