Skip to content
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

init:.Net 6版本初始化 #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Komi-Thaw
Copy link

No description provided.

@lindexi
Copy link
Member

lindexi commented Oct 20, 2022

@KomiSans 感谢贡献,似乎改格式的太多了,我没有找到核心的改动。如果可以的话,改格式的单独出来做一个 PR 如何?

@@ -125,10 +125,9 @@ public void Dispose()

private bool _isDisposed;

private readonly object _locker = new object();
private readonly object _locker = new();
Copy link
Member

Choose a reason for hiding this comment

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

由于采用源代码形式分发,考虑到源代码兼容性,不打算采用此语法特性

task = null;
while (_queue.Count > 0)
task = default;
while (_queue.Count is 0)
Copy link
Member

@lindexi lindexi Oct 20, 2022

Choose a reason for hiding this comment

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

这个逻辑是错误的

这里是不断获取队列内容

@@ -199,7 +201,7 @@ private bool TryGetNextTask(out AwaitableTask task)
task.SetNotExecutable();
}

return false;
return default;
Copy link
Member

Choose a reason for hiding this comment

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

对于布尔来说,使用 false 更加表意

@@ -30,15 +30,15 @@ class AwaitableTask
/// </summary>
public void SetNotExecutable()
{
Executable = false;
Executable = default;
Copy link
Member

Choose a reason for hiding this comment

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

对于布尔来说,使用 true 和 false 更加表意

}
// 如果不是空
// 那么设置任务完成
_waitForInitializationTask?.SetResult(true);
Copy link
Member

Choose a reason for hiding this comment

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

原本的写法是表示空和非空都在处理逻辑内,而且也方便加上断点进行调试。这个逻辑不做简化

// 根据 DoubleBufferTask 的设计,这个方法只有一个线程进入
FirstCheckInitialized: // 标签:第一个判断初始化方法
// 根据 DoubleBufferTask 的设计,这个方法只有一个线程进入
FirstCheckInitialized: // 标签:第一个判断初始化方法
Copy link
Member

Choose a reason for hiding this comment

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

这里用到部分 Goto 的方式,似乎对标签的缩进格式有所不同。我比较喜欢使用不缩进的方式,用来表示标签就是和其他代码不同

@@ -112,21 +105,19 @@ private async Task DoInner(List<T> dataList)
{
await _waitForInitializationTask!.Task.ConfigureAwait(false);
}
else
Copy link
Member

Choose a reason for hiding this comment

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

这个空 else 是用来表示另一个情况的,不简化哦

}
if (runningTaskList.Count <= MaxRunningCount) return;

if (WaitForFreeTask?.Task.IsCompleted is false) return;
Copy link
Member

Choose a reason for hiding this comment

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

这里的空逻辑是有意义的哦,不要省略了哦,表示两个情况都在逻辑预期内,且方便加上断点支持调试

这里是特意如此写的,还请不要简化

@@ -192,8 +192,10 @@ internal async Task RunAsync()
var task = _task();
if (task is null)
{
throw new InvalidOperationException("在指定 KeepLastReentrancyTask 的任务时,方法内不允许返回 null。请至少返回 Task.FromResult<object>(null)。");
throw new InvalidOperationException(
"在指定 KeepLastReentrancyTask 的任务时,方法内不允许返回 null。请至少返回 Task.FromResult<object>(null)。");
Copy link
Member

Choose a reason for hiding this comment

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

奇怪的换行逻辑,感觉不需要换行

{
/// <summary>
/// 在派生类中执行重入任务的时候,从此处获取需要执行的可重入异步任务。
/// </summary>
protected Func<TParameter, Task<TReturn>> WorkingTask { get; }
private Func<TParameter, Task<TReturn>> WorkingTask { get; }
Copy link
Member

Choose a reason for hiding this comment

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

这个是支持被业务方子类调用的哦,为什么这个要改动为私有?

Copy link
Member

@lindexi lindexi left a comment

Choose a reason for hiding this comment

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

感谢贡献,似乎看起来有一点小问题,期望修改

@Komi-Thaw
Copy link
Author

Komi-Thaw commented Oct 20, 2022 via email

@Komi-Thaw
Copy link
Author

感谢指正

@@ -6,6 +6,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>dotnetCampus.AsyncWorkerCollection</AssemblyName>
<LangVersion>8</LangVersion>
Copy link
Member

Choose a reason for hiding this comment

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

这个是不加的,因为将会作为源代码包分发

Copy link
Author

Choose a reason for hiding this comment

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

好的 我这边主要是为了使用Rider方便些加上去的

Copy link
Member

Choose a reason for hiding this comment

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

@KomiSans 好奇怪,居然你不用VS开发

Copy link
Author

Choose a reason for hiding this comment

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

Rider更智能一些其实

CurrentList = AList;
return BList;
}
CurrentList = ReferenceEquals(CurrentList, AList) ? AList : BList;
Copy link
Member

Choose a reason for hiding this comment

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

这里的逻辑需要两次判断,不如原先的

Copy link
Author

Choose a reason for hiding this comment

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

好的,我去改过来

@@ -87,9 +87,9 @@ public async ValueTask AddAsync(Task task)
/// 等待空闲
/// </summary>
/// <returns></returns>
public async ValueTask WaitForFree()
private async ValueTask WaitForFree()
Copy link
Member

Choose a reason for hiding this comment

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

这个看起来是非预期的

Copy link
Author

Choose a reason for hiding this comment

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

这个是提供客户方调用的么请问?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

好的

@@ -273,6 +277,7 @@ public bool AutoCancelPreviousTask
private bool _isDisposing;
private readonly ConcurrentQueue<AwaitableTask> _queue = new ConcurrentQueue<AwaitableTask>();
private readonly AsyncAutoResetEvent _autoResetEvent;

// ReSharper disable once RedundantDefaultMemberInitializer
Copy link
Author

Choose a reason for hiding this comment

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

请问,这个地方的初始化语法镇压有什么特殊含义么?

Copy link
Member

Choose a reason for hiding this comment

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

@Komi-Thaw 只是让 Resharper 开心而已

这里明确给定 _autoCancelPreviousTask 的初始值为 false 的值,和默认 bool 行为相同,此时 Resharper 没有理解意图,毕竟执行逻辑是等价的,于是提示这个 false 可以删除。但是这里我期望是明确给定 false 初始值,以便在后续有期望更改为 true 的时候,可以看到,之前的设计就是明确要 false 值

Copy link
Author

Choose a reason for hiding this comment

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

好的

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