Skip to content

Commit 1b4aa8c

Browse files
authored
Use Task.Run for more eager starting of parallel tasks (#793)
1 parent 27f7e4e commit 1b4aa8c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Use Task.Run for more eager starting of parallel tasks

src/ModularPipelines/Engine/ModuleExecutor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public async Task<IEnumerable<ModuleBase>> ExecuteAsync(IReadOnlyList<ModuleBase
7575
await ProcessKeyedNonParallelModules(keyedNonParallelModules.ToList());
7676

7777
var parallelModuleTasks = modules.Except(nonParallelModules)
78-
.Select(x => StartModule(x, false))
78+
.Select(x => Task.Run(() => StartModule(x, false)))
7979
.ToArray();
8080

8181
if (_pipelineOptions.Value.ExecutionMode == ExecutionMode.StopOnFirstException)
@@ -119,18 +119,18 @@ private async Task ProcessKeyedNonParallelModules(List<ModuleBase> keyedNonParal
119119
{
120120
await keyedNonParallelModules
121121
.OrderBy(x => x.GetType().GetCustomAttribute<NotInParallelAttribute>()!.ConstraintKeys.Length)
122-
.ForEachAsync(async module =>
122+
.ForEachAsync(module => Task.Run(async () =>
123123
{
124124
var keys = module.GetType()
125125
.GetCustomAttribute<NotInParallelAttribute>()!
126126
.ConstraintKeys
127127
.OrderBy(x => x)
128128
.ToArray();
129-
129+
130130
_logger.LogDebug("Grabbing not in parallel locks for keys {Keys}", string.Join(", ", keys));
131-
131+
132132
var locks = keys.Select(GetLockForKey).ToArray();
133-
133+
134134
while (!WaitHandle.WaitAll(locks, TimeSpan.FromMilliseconds(100), false))
135135
{
136136
await Task.Delay(TimeSpan.FromMilliseconds(500));
@@ -147,7 +147,7 @@ await keyedNonParallelModules
147147
semaphore.Release();
148148
}
149149
}
150-
})
150+
}))
151151
.ProcessInParallel();
152152
}
153153

0 commit comments

Comments
 (0)