@@ -9,14 +9,12 @@ namespace StackInjector.Core
99 internal abstract partial class AsyncStackWrapperCore < T >
1010 {
1111 // call the semaphore
12- protected internal void ReleaseListAwaiter ( )
13- {
14- this . emptyListAwaiter . Release ( ) ;
15- }
12+ protected internal void ReleaseListAwaiter ( ) => this . _emptyListAwaiter . Release ( ) ;
13+
1614
17- public void Submit ( Task < T > work )
15+ internal void Submit ( Task < T > work )
1816 {
19- lock ( this . listAccessLock )
17+ lock ( this . _listAccessLock )
2018 this . tasks . AddLast ( work ) ;
2119
2220 // if the list was empty just an item ago, signal it's not anymore.
@@ -25,31 +23,35 @@ public void Submit ( Task<T> work )
2523 this . ReleaseListAwaiter ( ) ;
2624 }
2725
26+
2827 public bool AnyTaskLeft ( )
2928 {
30- lock ( this . listAccessLock )
29+ lock ( this . _listAccessLock )
3130 return this . tasks . Any ( ) ;
3231 }
3332
3433 public bool AnyTaskCompleted ( )
3534 {
36- return this . tasks . Any ( t => t . IsCompleted ) ;
35+ lock ( this . _listAccessLock )
36+ return this . tasks . Any ( t => t . IsCompleted ) ;
3737 }
3838
3939 // todo add a method to safely exit the await loop to be able to re-join later or maybe an Unloack() of some sort
4040 //! should check if exiting an await foreach loop and re-entering will not hack the control or lose data
4141 public async IAsyncEnumerable < T > Elaborated ( )
4242 {
4343 this . EnsureExclusiveExecution ( true ) ;
44-
44+
4545 while ( ! this . cancelPendingTasksSource . IsCancellationRequested )
4646 {
4747 // avoid deadlocks
4848 if ( this . AnyTaskLeft ( ) )
4949 {
5050 var completed = await Task . WhenAny ( this . tasks ) . ConfigureAwait ( false ) ;
5151
52- lock ( this . listAccessLock )
52+
53+
54+ lock ( this . _listAccessLock )
5355 this . tasks . Remove ( completed ) ;
5456
5557 yield return completed . Result ;
@@ -62,24 +64,15 @@ public async IAsyncEnumerable<T> Elaborated ()
6264 }
6365 }
6466
65- lock ( this . listAccessLock )
66- this . exclusiveExecution = false ;
67+ lock ( this . _listAccessLock )
68+ this . _exclusiveExecution = false ;
6769
6870 }
6971
70- public Task Elaborate ( )
72+ public async Task Elaborate ( )
7173 {
72- // must run syncronously
73- this . EnsureExclusiveExecution ( ) ;
74-
75- return
76- Task . Run ( async ( ) =>
77- {
78-
79- await foreach ( var res in this . Elaborated ( ) )
80- this . OnElaborated ? . Invoke ( res ) ;
81- } ) ;
82-
74+ await foreach ( var res in this . Elaborated ( ) )
75+ this . OnElaborated ? . Invoke ( res ) ;
8376 }
8477
8578
@@ -88,7 +81,7 @@ private async Task<bool> OnNoTasksLeft ()
8881 {
8982 // to not repeat code
9083 Task listAwaiter ( )
91- => this . emptyListAwaiter . WaitAsync ( ) ;
84+ => this . _emptyListAwaiter . WaitAsync ( ) ;
9285
9386
9487 switch ( this . Settings . _asyncWaitingMethod )
@@ -118,13 +111,13 @@ Task listAwaiter ()
118111
119112 private void EnsureExclusiveExecution ( bool set = false )
120113 {
121- lock ( this . listAccessLock ) // reused lock
114+ lock ( this . _listAccessLock ) // reused lock
122115 {
123- if ( this . exclusiveExecution )
116+ if ( this . _exclusiveExecution )
124117 throw new InvalidOperationException ( ) ;
125118
126119 if ( set )
127- this . exclusiveExecution = set ;
120+ this . _exclusiveExecution = set ;
128121 }
129122 }
130123
0 commit comments