Conversation
| /// </summary> | ||
| /// <returns>Function result</returns> | ||
| /// <exception cref="Exception">If delegate threw exception</exception> | ||
| public T Get() |
There was a problem hiding this comment.
Тут и в другой реализации компилятор недоволен nullability-анализом, надо исправить
| /// <summary> | ||
| /// Delegate defining the lazy | ||
| /// </summary> | ||
| private readonly Func<T> _supplier; |
There was a problem hiding this comment.
Нужен перенос полей (см. Умножение матриц)
| /// </summary> | ||
| /// <returns>Function result</returns> | ||
| /// <exception cref="Exception">If delegate threw exception</exception> | ||
| public T Get() |
There was a problem hiding this comment.
Здесь и в многопоточной реализации стоит еще supplier после вычисления занулить, чтобы сборщик мусора смог собрать объект
C#/forSpbu/Lazy.Tests/LazyTests.cs
Outdated
| { | ||
| public int CallCounter; | ||
|
|
||
| public int FstTest() |
There was a problem hiding this comment.
Этим функциям стоит присвоить более осмысленные и говорящие имена, хоть они и для тестов нужны
C#/forSpbu/Lazy.Tests/LazyTests.cs
Outdated
| } | ||
| } | ||
|
|
||
| private static IEnumerable<TestCaseData> IntLazyImpl() |
There was a problem hiding this comment.
Это не домашка на Rust :)
Так что impl -> implementation
C#/forSpbu/Lazy.Tests/LazyTests.cs
Outdated
|
|
||
| private class LazyTester | ||
| { | ||
| public int CallCounter; |
There was a problem hiding this comment.
Похоже { get; } затерялось :)
Иначе это public-поле
C#/forSpbu/Lazy.Tests/LazyTests.cs
Outdated
| var tester = new LazyTester(); | ||
| var lazy = new MultiThreadedLazy<int>(tester.FstTest); | ||
|
|
||
| var threads = new Thread[4]; |
There was a problem hiding this comment.
Да можно и потоков 10 создать, чего мелочиться :)
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(lazy.Get(), Is.EqualTo(1)); | ||
| Assert.That(tester.CallCounter, Is.EqualTo(1)); |
There was a problem hiding this comment.
Стоит добавить в тест ManualResetEvent, чтобы увеличить вероятность того, что все потоки отправятся получать значение в одно и то же время
There was a problem hiding this comment.
Кстати, CallCounter тогда volatile должен быть. А лучше вообще в функциях ++ на Interlocked.Increment заменить и с volatile не возиться
No description provided.