@@ -93,6 +93,7 @@ public InitializationTracker(bool hasInitializers, bool hasSynchronizers, bool h
9393 // If we have no data sources, then we are immediately initialized.
9494 _state = State . Initialized ;
9595 _taskCompletionSource . TrySetResult ( true ) ;
96+ return ;
9697 }
9798
9899 _initializersRemain = hasInitializers ;
@@ -121,7 +122,9 @@ private void DetermineState(Action action)
121122 {
122123 switch ( _state )
123124 {
125+ // Terminal states, ignore subsequent actions.
124126 case State . Initialized :
127+ case State . Failed :
125128 break ;
126129 case State . NoData :
127130 switch ( action )
@@ -145,8 +148,6 @@ private void DetermineState(Action action)
145148 _fallbackRemain = false ;
146149 HandleRemainingSources ( ) ;
147150 break ;
148- default :
149- throw new ArgumentOutOfRangeException ( nameof ( action ) , action , null ) ;
150151 }
151152
152153 break ;
@@ -161,8 +162,6 @@ private void DetermineState(Action action)
161162 case Action . SelectorReceived :
162163 _state = State . Initialized ;
163164 break ;
164- default :
165- throw new ArgumentOutOfRangeException ( nameof ( action ) , action , null ) ;
166165 }
167166
168167 break ;
@@ -183,18 +182,21 @@ private void DetermineState(Action action)
183182 case Action . SelectorReceived :
184183 _state = State . Initialized ;
185184 break ;
186- default :
187- throw new ArgumentOutOfRangeException ( nameof ( action ) , action , null ) ;
188185 }
189186
190-
191187 break ;
192- default :
193- throw new ArgumentOutOfRangeException ( ) ;
194188 }
195189
196- if ( _state == State . Initialized ) _taskCompletionSource . TrySetResult ( true ) ;
197- if ( _state == State . Failed ) _taskCompletionSource . TrySetResult ( false ) ;
190+ // After updating the state determine if we need to complete the task.
191+ switch ( _state )
192+ {
193+ case State . Initialized :
194+ _taskCompletionSource . TrySetResult ( true ) ;
195+ break ;
196+ case State . Failed :
197+ _taskCompletionSource . TrySetResult ( false ) ;
198+ break ;
199+ }
198200 }
199201
200202 public void Apply ( DataStoreTypes . ChangeSet < DataStoreTypes . ItemDescriptor > changeSet , bool exhausted ,
0 commit comments