samber / do

βš™οΈ A dependency injection toolkit based on Go 1.18+ Generics.
https://pkg.go.dev/github.com/samber/do
MIT License
1.71k stars 67 forks source link

[πŸ‘·] Road to v2 πŸš€ - Refactor DAG Maps to sync.Map and Improve invoke Function Readability #48

Closed K4L1Ma closed 7 months ago

K4L1Ma commented 7 months ago

This PR introduces improvements to the codebase by replacing certain maps and mutexes with sync.Map for enhanced concurrency safety. Additionally, modifications have been made to the invoke function to improve its readability, making the code more comprehensible.

Relates to https://github.com/samber/do/pull/45

Changes:

Utilization of sync.Map:

Replaced existing maps and mutexes with sync.Map for improved concurrency handling. This enhances the safety and efficiency of the code, particularly in scenarios involving concurrent access to maps.

Enhanced invoke Function:

Made changes to the invoke function to enhance readability. Improved the structure and clarity of the code for easier understanding and maintenance.

Purpose:

The goal of these changes is to enhance the overall robustness and clarity of the codebase. The adoption of sync.Map improves concurrent map operations, while the refactoring of the invoke function aims to make the code more legible and maintainable.

Testing:

The changes have been tested to ensure that the refactored code retains its functionality and performs as expected. Unit tests have been executed to validate the correctness of the modifications.

codecov-commenter commented 7 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (97bcede) 82.96% compared to head (2cf81c8) 83.06%.

Files Patch % Lines
virtual_scope.go 91.66% 1 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## v2-πŸš€ #48 +/- ## ========================================== + Coverage 82.96% 83.06% +0.10% ========================================== Files 21 21 Lines 1438 1453 +15 ========================================== + Hits 1193 1207 +14 - Misses 217 218 +1 Partials 28 28 ``` | [Flag](https://app.codecov.io/gh/samber/do/pull/48/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Berthe) | Coverage Ξ” | | |---|---|---| | [unittests](https://app.codecov.io/gh/samber/do/pull/48/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Berthe) | `83.06% <98.98%> (+0.10%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Samuel+Berthe#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

samber commented 7 months ago

Thanks for this improvement and above all, for making it more readable. 😁