File tree Expand file tree Collapse file tree
Winton.Extensions.Threading.Actor/Internal/StateMachine Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ protected override void StopImpl()
6464
6565 protected override void EnterImpl ( )
6666 {
67+ Context . StartCompletionSource . SetResult ( true ) ;
68+
6769 foreach ( var task in Context . InitialWorkQueue )
6870 {
6971 Context . StartTask ( task ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ public ActorContext(IActorTaskFactory actorTaskFactory)
2525
2626 public List < Task > InitialWorkQueue { get ; } = new List < Task > ( ) ;
2727
28+ public List < Task > InitialWorkToBeCancelledQueue { get ; } = new List < Task > ( ) ;
29+
2830 public IActorTaskFactory ActorTaskFactory { get ; }
2931
3032 public ActorStartWork StartWork
Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ protected override void StartImpl()
1919 }
2020 else
2121 {
22- Context . StartCompletionSource . SetResult ( true ) ;
2322 Context . SetState < ActiveActorState > ( ) ;
2423 }
2524 }
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ protected override void EnterImpl()
3434 {
3535 await task . ConfigureAwait ( false ) ;
3636
37- Context . StartCompletionSource . SetResult ( true ) ;
3837 Context . SetState < ActiveActorState > ( ) ;
3938
4039 if ( ReceivedStopSignal )
@@ -62,7 +61,14 @@ protected override void EnterImpl()
6261
6362 protected override void ScheduleImpl ( Task task )
6463 {
65- Context . InitialWorkQueue . Add ( task ) ;
64+ if ( ! ReceivedStopSignal )
65+ {
66+ Context . InitialWorkQueue . Add ( task ) ;
67+ }
68+ else
69+ {
70+ Context . InitialWorkToBeCancelledQueue . Add ( task ) ;
71+ }
6672 }
6773
6874 private bool ReceivedStopSignal { get ; set ; } = false ;
Original file line number Diff line number Diff line change 1+ using System . Linq ;
12using System . Threading . Tasks ;
23
34namespace Winton . Extensions . Threading . Actor . Internal . StateMachine
@@ -24,12 +25,13 @@ protected override void StopImpl()
2425
2526 protected override void EnterImpl ( )
2627 {
27- foreach ( var task in Context . InitialWorkQueue )
28+ foreach ( var task in Context . InitialWorkQueue . Concat ( Context . InitialWorkToBeCancelledQueue ) )
2829 {
2930 task . Cancel ( ) ;
3031 }
3132
3233 Context . InitialWorkQueue . Clear ( ) ;
34+ Context . InitialWorkToBeCancelledQueue . Clear ( ) ;
3335 }
3436 }
3537}
You can’t perform that action at this time.
0 commit comments