Skip to content

Commit d476798

Browse files
authored
+semver:minor - Simplify Starting Modules (#361)
* Simplify Starting Modules * Formatting Markdown --------- Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com>
1 parent 2cb4eb7 commit d476798

File tree

4 files changed

+14
-36
lines changed

4 files changed

+14
-36
lines changed

src/ModularPipelines/Engine/Executors/ModuleHandlers/SkipHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public async Task SetSkipped(SkipDecision skipDecision)
2424
{
2525
return;
2626
}
27-
28-
Module.ExecutionTask = ModuleResultTaskCompletionSource.Task;
2927

3028
CallbackTask.Start(TaskScheduler.Default);
3129

src/ModularPipelines/Engine/ModuleExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public async Task<ModuleBase> ExecuteAsync(ModuleBase module)
8383
{
8484
await _pipelineSetupExecutor.OnBeforeModuleStartAsync(module);
8585

86-
await module.StartAsync();
86+
await module.ExecutionTask;
8787

8888
await _moduleEstimatedTimeProvider.SaveModuleTimeAsync(module.GetType(), module.Duration);
8989

src/ModularPipelines/Modules/Module.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public abstract partial class Module<T> : ModuleBase<T>
2424
{
2525
private readonly Stopwatch _stopwatch = new();
2626
private readonly object _startCheckLock = new();
27-
private readonly object _triggerLock = new();
2827

2928
internal override IHistoryHandler<T> HistoryHandler { get; }
3029

@@ -61,20 +60,6 @@ protected Module()
6160
}
6261
}
6362

64-
/// <summary>
65-
/// Used to start, run, and control the flow of a Module, including handling exceptions and skipping.
66-
/// </summary>
67-
/// <exception cref="ModuleFailedException">Thrown if the module has failed and the failure was not ignored.</exception>
68-
[StackTraceHidden]
69-
internal override Task StartAsync()
70-
{
71-
lock (_startCheckLock)
72-
{
73-
IsStarted = true;
74-
return ExecutionTask;
75-
}
76-
}
77-
7863
internal override ModuleBase Initialize(IPipelineContext context)
7964
{
8065
context.InitializeLogger(GetType());
@@ -102,20 +87,20 @@ internal override Task ExecutionTask
10287
[StackTraceHidden]
10388
get
10489
{
105-
lock (_triggerLock)
90+
lock (_startCheckLock)
10691
{
107-
_executionTaskInternal ??= StartInternal();
92+
if (!IsStarted)
93+
{
94+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
95+
StartInternal();
96+
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
97+
}
98+
99+
IsStarted = true;
100+
108101
return ModuleResultTaskCompletionSource.Task;
109102
}
110103
}
111-
112-
set
113-
{
114-
lock (_triggerLock)
115-
{
116-
_executionTaskInternal = value;
117-
}
118-
}
119104
}
120105

121106
/// <summary>
@@ -187,8 +172,6 @@ private void AddDependency(DependsOnAttribute dependsOnAttribute)
187172
DependentModules.Add(dependsOnAttribute);
188173
}
189174

190-
private Task? _executionTaskInternal;
191-
192175
[StackTraceHidden]
193176
private async Task StartInternal()
194177
{

src/ModularPipelines/Modules/ModuleBase.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ protected ModuleBase()
2626
TypeDiscriminator = GetType().FullName!;
2727
}
2828

29-
internal bool IsStarted { get; set; }
29+
internal bool IsStarted { get; private protected set; }
3030

31-
internal List<DependsOnAttribute> DependentModules { get; } = new();
31+
internal List<DependsOnAttribute> DependentModules { get; } = [];
3232

3333
internal abstract IWaitHandler WaitHandler { get; }
3434

@@ -73,7 +73,7 @@ protected set
7373
[JsonInclude]
7474
internal SkipDecision SkipResult { get; set; } = SkipDecision.DoNotSkip;
7575

76-
internal abstract Task ExecutionTask { get; set; }
76+
internal abstract Task ExecutionTask { get; }
7777

7878
internal readonly CancellationTokenSource ModuleCancellationTokenSource = new();
7979

@@ -103,9 +103,6 @@ protected set
103103

104104
internal Exception? Exception { get; set; }
105105

106-
[StackTraceHidden]
107-
internal abstract Task StartAsync();
108-
109106
internal abstract ModuleBase Initialize(IPipelineContext context);
110107

111108
internal readonly List<SubModuleBase> SubModuleBases = new();

0 commit comments

Comments
 (0)