From bdee37164d5b3074de8644eaf165b2b9ec144660 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Sun, 20 Aug 2023 22:17:56 +0800 Subject: [PATCH 1/3] feat: use false for exit token source cancel --- src/WeihanLi.Common/Helpers/InvokeHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WeihanLi.Common/Helpers/InvokeHelper.cs b/src/WeihanLi.Common/Helpers/InvokeHelper.cs index 8968d58f..fabb2335 100644 --- a/src/WeihanLi.Common/Helpers/InvokeHelper.cs +++ b/src/WeihanLi.Common/Helpers/InvokeHelper.cs @@ -119,7 +119,7 @@ private static void InvokeExitHandler(object? sender, EventArgs? args) Debug.WriteLine("exiting..."); if (LazyCancellationTokenSource.IsValueCreated) { - LazyCancellationTokenSource.Value.Cancel(); + LazyCancellationTokenSource.Value.Cancel(false); LazyCancellationTokenSource.Value.Dispose(); } Debug.WriteLine("exited"); From b35a2a8d7910d6e1f66aff827dbf30297a6db217 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Sun, 20 Aug 2023 22:22:53 +0800 Subject: [PATCH 2/3] refactor: remove TaskHelper.CompletedValueTask --- .../Helpers/PipelineBuilder.cs | 2 +- src/WeihanLi.Common/Helpers/TaskHelper.cs | 20 +++++++------------ src/WeihanLi.Common/NullDisposable.cs | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/WeihanLi.Common/Helpers/PipelineBuilder.cs b/src/WeihanLi.Common/Helpers/PipelineBuilder.cs index 1d9b3c50..4486e276 100644 --- a/src/WeihanLi.Common/Helpers/PipelineBuilder.cs +++ b/src/WeihanLi.Common/Helpers/PipelineBuilder.cs @@ -32,7 +32,7 @@ public static IValueAsyncPipelineBuilder CreateValueAsync() #if NET6_0_OR_GREATER ValueTask.CompletedTask #else - TaskHelper.CompletedValueTask + default(ValueTask) #endif ); } diff --git a/src/WeihanLi.Common/Helpers/TaskHelper.cs b/src/WeihanLi.Common/Helpers/TaskHelper.cs index 2380fa9e..95ad6a4a 100644 --- a/src/WeihanLi.Common/Helpers/TaskHelper.cs +++ b/src/WeihanLi.Common/Helpers/TaskHelper.cs @@ -5,25 +5,19 @@ namespace WeihanLi.Common.Helpers; public static class TaskHelper { -#if ValueTaskSupport - /// - /// A cached completed value task - /// - public static ValueTask CompletedValueTask => -#if NET6_0_OR_GREATER - ValueTask.CompletedTask -#else - default -#endif - ; - +#if ValueTaskSupport public static ValueTask ToTask(object? obj) { var task = obj switch { ValueTask vt => vt, Task t => new ValueTask(t), - _ => CompletedValueTask + _ => +#if NET6_0_OR_GREATER + ValueTask.CompletedTask +#else + default +#endif }; return task; } diff --git a/src/WeihanLi.Common/NullDisposable.cs b/src/WeihanLi.Common/NullDisposable.cs index e89345f9..f805792e 100644 --- a/src/WeihanLi.Common/NullDisposable.cs +++ b/src/WeihanLi.Common/NullDisposable.cs @@ -23,7 +23,7 @@ public ValueTask DisposeAsync() => #if NET6_0_OR_GREATER ValueTask.CompletedTask #else - TaskHelper.CompletedValueTask + default(ValueTask) #endif ; #endif From 8445d31c68733a1e10490b62d039b4875a61fda8 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Sun, 20 Aug 2023 22:24:45 +0800 Subject: [PATCH 3/3] ci: move dotnet-format to post-push --- .husky/post-push | 22 ++++++++++++++++++++++ .husky/task-runner.json | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .husky/post-push diff --git a/.husky/post-push b/.husky/post-push new file mode 100644 index 00000000..b7eaeba9 --- /dev/null +++ b/.husky/post-push @@ -0,0 +1,22 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +## husky task runner examples ------------------- +## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' + +## run all tasks +#husky run + +### run all tasks with group: 'group-name' +#husky run --group group-name + +## run task with name: 'task-name' +#husky run --name task-name + +## pass hook arguments to task +#husky run --args "$1" "$2" + +## or put your custom commands ------------------- +#echo 'Husky.Net is awesome!' + +dotnet husky run --group post-push diff --git a/.husky/task-runner.json b/.husky/task-runner.json index 4493d17a..ef58e861 100644 --- a/.husky/task-runner.json +++ b/.husky/task-runner.json @@ -6,16 +6,7 @@ "group": "commit-msg", "command": "dotnet-exec", "args": [".husky/scripts/commit-lint.cs", "--args", "${args}"] - }, - { - "name": "dotnet-format", - "group": "pre-push", - "command": "dotnet", - "args": [ "format" ], - "include": [ - "**/*.cs" - ] - }, + }, { "name": "test", "group": "pre-push", @@ -25,6 +16,15 @@ "**/*.md", "docs/**/*" ] + }, + { + "name": "dotnet-format", + "group": "post-push", + "command": "dotnet", + "args": [ "format" ], + "include": [ + "**/*.cs" + ] } ] }