Skip to content

Conversation

@Andrw-404
Copy link
Owner

No description provided.

Comment on lines 5 to 6
namespace LazyInterface
{

Choose a reason for hiding this comment

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

используйте file-scoped неймспейсы

Suggested change
namespace LazyInterface
{
namespace LazyInterface;


private T? result;

private bool flag;

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;

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;

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);

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()

Choose a reason for hiding this comment

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

Чтобы не дублировать тесты на общее поведение для двух реализаций, используйте TestCaseSource для передачи реализаций и интерфейс ILazy в каждом общем тесте

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.

2 participants