File tree 3 files changed +36
-13
lines changed
3 files changed +36
-13
lines changed Original file line number Diff line number Diff line change @@ -196,23 +196,39 @@ public async ValueTask Update(bool parallel = true)
196
196
if ( _disposed )
197
197
throw new InvalidOperationException ( "Context disposed." ) ;
198
198
199
+ // if empty, return
200
+ if ( _executeSystems . Count == 0 )
201
+ return ;
202
+
199
203
// clear the cache of the groups
200
204
InvalidateGroupCache ( ) ;
201
- // execute the systems
202
- _executeTasks . Clear ( ) ;
203
- // sort by priority
204
- foreach ( var system in _executeSystems . Values )
205
+ // group by priority
206
+ int remaining = _executeSystems . Count ;
207
+ int index = 0 ;
208
+ while ( remaining > 0 )
205
209
{
206
- _executeTasks . Add ( parallel ? Task . Run ( ( ) => system . Update ( this ) ) : system . Update ( this ) ) ;
207
- }
210
+ // execute the systems with the same priority
211
+ _executeTasks . Clear ( ) ;
212
+ ExecuteSystemWrapper system = _executeSystems . Values [ index ] ;
213
+ var currentPriority = system . Priority ;
214
+ while ( system . Priority == currentPriority && remaining > 0 )
215
+ {
216
+ var systemWrapper = system ;
217
+ _executeTasks . Add ( parallel ? Task . Run ( ( ) => systemWrapper . Update ( this ) ) : systemWrapper . Update ( this ) ) ;
218
+ index ++ ;
219
+ if ( -- remaining > 0 )
220
+ system = _executeSystems . Values [ index ] ;
221
+ }
208
222
209
- try
210
- {
211
- await Task . WhenAll ( _executeTasks ) ;
212
- }
213
- catch ( Exception e )
214
- {
215
- OnError ? . Invoke ( e ) ;
223
+ // dispatch all tasks of the same priority
224
+ try
225
+ {
226
+ await Task . WhenAll ( _executeTasks ) ;
227
+ }
228
+ catch ( Exception e )
229
+ {
230
+ OnError ? . Invoke ( e ) ;
231
+ }
216
232
}
217
233
218
234
while ( _removeList . TryDequeue ( out var entity ) )
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ internal class ExecuteSystemWrapper
11
11
private readonly IExecuteSystem _system ;
12
12
private int _counter ;
13
13
14
+ internal int Priority => ( ( SystemBase ) _system ) . Priority ;
15
+
14
16
public ExecuteSystemWrapper ( IExecuteSystem system )
15
17
{
16
18
_system = system ;
Original file line number Diff line number Diff line change 4
4
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AReadOnlyCollection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4cfef46534ca7afeaf461953f17dc5b92a0173671794e94d93bbe487d37f4a_003FReadOnlyCollection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
5
5
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASocket_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F611efef9cc4db44681420ed548e67f2174d4f12bb94a911f6f81a4ba7ca_003FSocket_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
6
6
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASortedList_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fd08c4c7cd56e410ba2f228947c6bfcc349200_003F6d_003Fab004b16_003FSortedList_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
7
+ <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ca59a3c6_002D1b78_002D4f89_002D9b6e_002Df9f35114ecb0/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="SimpleTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
8
+ <TestAncestor>
9
+ <TestId>NUnit3x::FDA284F0-DE3A-4C46-A8B9-90324F25FCB0::net6.0::EasyEcs.UnitTest.SimpleTest</TestId>
10
+ </TestAncestor>
11
+ </SessionState></s:String>
7
12
8
13
9
14
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fabae239_002Dedef_002D47f4_002Da7cb_002D6b40f5828ca8/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Tests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
You can’t perform that action at this time.
0 commit comments