Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 331
Better Async Effect Cleanup #956
Copy link
Copy link
Closed
Labels
priority-2-moderateShould be resolved on a reasonable timeline.Should be resolved on a reasonable timeline.release-patchWarrents a patch releaseWarrents a patch releasetype-revisionAbout a change in functionality or behaviorAbout a change in functionality or behavior
Description
Metadata
Metadata
Assignees
Labels
priority-2-moderateShould be resolved on a reasonable timeline.Should be resolved on a reasonable timeline.release-patchWarrents a patch releaseWarrents a patch releasetype-revisionAbout a change in functionality or behaviorAbout a change in functionality or behavior
Current Situation
Presently, the "cleanup" behavior for async effects is that they are cancelled before the next effect takes place or the component is unmounted. While this behavior may be desirable in many cases, it does not give the user the ability to gracefully deal with cleanup logic in the way one can with a sync event.
For example, consider a long running async effect:
The problem with this current behavior is that handling the cancellation is messy. You could do the following:
However, this may lead to some confusing behavior since it's not possible to know whether
something()orsomething_else()will receive the cancellation. You might have to do a lot of extra work to figure out what state your program was left in after the cancellation.Proposed Actions
Thankfully the above only impacts async effects. With a synchronous event, you would be able to handle async task cleanup using something like the following:
Given this, our proposed solution to the problem is to allow async effects to accept a similar interupt
asyncio.Event: