Fix ReAwaitable to support concurrent await calls (#2108)#2150
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix ReAwaitable to support concurrent await calls
This PR adds thread-safe caching with asyncio.Lock to prevent race conditions when multiple tasks await the same ReAwaitable instance concurrently. The implementation maintains backward compatibility for non-asyncio environments.
Changes made:
Why this change is needed:
Previously, when multiple async tasks awaited the same ReAwaitable instance simultaneously, race conditions could occur leading to the underlying coroutine being executed multiple times. This fix ensures that only one task executes the coroutine while others wait and receive the cached result.
Checklist
Related issues
🙏 Please, if you or your company finds dry-python valuable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.