55
66namespace StackInjector . Core
77{
8- internal abstract partial class AsyncStackWrapperCore < T > : StackWrapperCore , IAsyncStackWrapperCore < T >
9- {
8+ internal abstract partial class AsyncStackWrapperCore < T > : StackWrapperCore , IAsyncStackWrapperCore < T >
9+ {
1010
11- public event Action < T > OnElaborated ;
11+ public event Action < T > OnElaborated ;
1212
1313
14- // used to cancel everything
15- protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource ( ) ;
14+ // used to cancel everything
15+ protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource ( ) ;
1616
17- // exposes the token
18- public CancellationToken PendingTasksCancellationToken
19- => this . cancelPendingTasksSource . Token ;
17+ // exposes the token
18+ public CancellationToken PendingTasksCancellationToken
19+ => this . cancelPendingTasksSource . Token ;
2020
21- // used to lock access to tasks
22- private readonly object _listAccessLock = new object ( ) ;
21+ // used to lock access to tasks
22+ private readonly object _listAccessLock = new object ( ) ;
2323
24- // used to endure Elaborated() and Elaborate() are called together
25- private bool _exclusiveExecution ;
24+ // used to endure Elaborated() and Elaborate() are called together
25+ private bool _exclusiveExecution ;
2626
27- public bool IsElaborating => this . _exclusiveExecution ;
27+ public bool IsElaborating => this . _exclusiveExecution ;
2828
29- // asyncronously waited for new events if TaskList is empty
30- private readonly SemaphoreSlim _emptyListAwaiter = new SemaphoreSlim ( 0 ) ;
29+ // asyncronously waited for new events if TaskList is empty
30+ private readonly SemaphoreSlim _emptyListAwaiter = new SemaphoreSlim ( 0 ) ;
3131
32- // pending tasks
33- protected internal LinkedList < Task < T > > tasks = new LinkedList < Task < T > > ( ) ;
32+ // pending tasks
33+ protected internal LinkedList < Task < T > > tasks = new LinkedList < Task < T > > ( ) ;
3434
3535
36- // register an event that in case the list is empty, release the empty event listener.
37- internal AsyncStackWrapperCore ( InjectionCore core , Type toRegister ) : base ( core , toRegister ) =>
38- this . cancelPendingTasksSource . Token . Register ( this . ReleaseListAwaiter ) ;
36+ // register an event that in case the list is empty, release the empty event listener.
37+ internal AsyncStackWrapperCore ( InjectionCore core , Type toRegister ) : base ( core , toRegister )
38+ {
39+ this . cancelPendingTasksSource . Token . Register ( this . ReleaseListAwaiter ) ;
40+ }
3941
4042
4143
42- #region IDisposable Support
44+ #region IDisposable Support
4345
44- private bool disposedValue ;
46+ private bool disposedValue ;
4547
46- public override void Dispose ( )
47- {
48- if ( ! this . disposedValue )
49- {
48+ public override void Dispose ( )
49+ {
50+ if ( ! this . disposedValue )
51+ {
5052
51- // managed resources
52- this . cancelPendingTasksSource . Cancel ( ) ; // cancel all pending tasks
53- this . ReleaseListAwaiter ( ) ; // in case it's waiting on the empty list
53+ // managed resources
54+ this . cancelPendingTasksSource . Cancel ( ) ; // cancel all pending tasks
55+ this . ReleaseListAwaiter ( ) ; // in case it's waiting on the empty list
5456
55- this . cancelPendingTasksSource . Dispose ( ) ;
56- this . _emptyListAwaiter . Dispose ( ) ;
57+ this . cancelPendingTasksSource . Dispose ( ) ;
58+ this . _emptyListAwaiter . Dispose ( ) ;
5759
5860
59- // big objects
60- this . tasks . Clear ( ) ;
61- this . tasks = null ;
61+ // big objects
62+ this . tasks . Clear ( ) ;
63+ this . tasks = null ;
6264
63- // clean instantiated objects
64- this . Core . RemoveInstancesDiff ( ) ;
65+ // clean instantiated objects
66+ this . Core . RemoveInstancesDiff ( ) ;
6567
6668
67- this . disposedValue = true ;
68- }
69- }
70- #endregion
71- }
69+ this . disposedValue = true ;
70+ }
71+ }
72+ #endregion
73+ }
7274
7375}
0 commit comments