Is there a reference to the active generator that runs the flow? I need that in order to cancel node fetches before the node is destroyed.
@elite174 would you mind taking a look at the tests in #691 and indicate whether this would a solution for your problem?
Thanks!
@mweststrate Sure, I will! Thank you!
I looked at the PR, and that's really great. However, I have one question: is there a way to get the running flow? I want this flow in order to cancel it before the node is destroyed.
Something like this:
const M = types.model({})
.actions(self => ({
beforeDestroy(){
self.runningFlow.cancel()
},
// some actions here
}))
@elite174 not in that way, as there might be many flows running, not just one. But you could do this:
If this pattern works well, we could consider building it in somehow.
.actions(self => {
let pendingPromises = []
const myFlow = flow(function* () {})
return {
beforeDestroy() {
pendingPromises.forEach(p => p.cancel())
},
myFlow: function() {
const p = myFlow.apply(null, arguments)
pendingPromises.push(p)
return p
}
}
}
Oh, wow! That's what I was looking for! Thank you very much.
Closing for now as there is an open PR, but question is answered.
Most helpful comment
@elite174 not in that way, as there might be many flows running, not just one. But you could do this:
If this pattern works well, we could consider building it in somehow.