Skip to content

Fix: Async resolving the shared instances (avoiding duplicates) (3/3)#24

Merged
DanielCech merged 21 commits intomasterfrom
feat/async-shared-instances
Mar 6, 2026
Merged

Fix: Async resolving the shared instances (avoiding duplicates) (3/3)#24
DanielCech merged 21 commits intomasterfrom
feat/async-shared-instances

Conversation

@DanielCech
Copy link
Copy Markdown
Member

@DanielCech DanielCech commented Jan 15, 2026

This PR is a bit unexpected. I implemented some async tests, and especially tests for async resolving of the group of shared dependencies (concurrentResolveSharedDependency) were failing. It is not a very common case that we need to resolve so many same shared dependencies at the same time, but it is worth fixing.

Problem:
The test was failing because multiple concurrent resolves were all creating their own shared instance.
In the original AsyncContainer logic: getDependency checks sharedInstances. If missing, it awaits the factory. After await, it stores the shared instance. When several tasks hit this at once, they all pass the “no instance yet” check, and each one builds its own instance before any of them stores it.

Solution
Added a task cache for shared resolutions in AsyncContainer, so it resolves await the same Task instead of creating duplicates.
The shared instance is now stored once the task completes, and the cache entry is cleared (also on errors).
This ensures all concurrent shared resolves return the same instance.

This PR is built on top of #23

@DanielCech DanielCech marked this pull request as ready for review January 15, 2026 14:28
robha141
robha141 previously approved these changes Jan 16, 2026
Copy link
Copy Markdown
Contributor

@robha141 robha141 left a comment

Choose a reason for hiding this comment

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

🐝

@DanielCech DanielCech changed the title Fix: Async resolving the shared instances (avoiding duplicates) Fix: Async resolving the shared instances (avoiding duplicates) (4/4) Feb 4, 2026
@DanielCech DanielCech changed the title Fix: Async resolving the shared instances (avoiding duplicates) (4/4) Fix: Async resolving the shared instances (avoiding duplicates) (3/3) Feb 9, 2026
TParizek
TParizek previously approved these changes Feb 17, 2026
Copy link
Copy Markdown
Contributor

@TParizek TParizek left a comment

Choose a reason for hiding this comment

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

Awesome fix for that concurrency issue! It’s great to see us taking full advantage of Swift Structured Concurrency here.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 6, 2026

1 Warning
⚠️ Big PR - you should create smaller!

Generated by 🚫 Danger

Base automatically changed from feat/swift-testing to master March 6, 2026 12:25
@DanielCech DanielCech dismissed stale reviews from TParizek and robha141 March 6, 2026 12:25

The base branch was changed.

@DanielCech DanielCech merged commit e70e77a into master Mar 6, 2026
2 checks passed
@DanielCech DanielCech deleted the feat/async-shared-instances branch March 6, 2026 12:36
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