-
Notifications
You must be signed in to change notification settings - Fork 0
Lazy #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
LazyInterface/LazyInterface/ILazy.cs
Outdated
| namespace LazyInterface | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
используйте file-scoped неймспейсы
| namespace LazyInterface | |
| { | |
| namespace LazyInterface; |
|
|
||
| private T? result; | ||
|
|
||
| private bool flag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isCalculated лучше
| ArgumentNullException.ThrowIfNull(supplier); | ||
|
|
||
| this.supplier = supplier; | ||
| this.flag = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это можно не писать -- дефолтное значение для boolean-поля
| this.supplier = null; | ||
| } | ||
|
|
||
| return this.result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чтобы линтер не ругался, лучше пометить возвращаемый тип как T?
| var lazy = new MultithreadedVersion<object>(() => | ||
| { | ||
| Interlocked.Increment(ref callCount); | ||
| Thread.Sleep(150); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чтобы просимулировать одновременный старт потоков, используйте manualResetEvent или Barrier
| public class SingleThreadedTests | ||
| { | ||
| [Test] | ||
| public void Get_MultipleCalls_ShoulCallSupplierOnlyOnceAndReturnCorrectValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чтобы не дублировать тесты на общее поведение для двух реализаций, используйте TestCaseSource для передачи реализаций и интерфейс ILazy в каждом общем тесте
No description provided.