This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -754,7 +754,11 @@ const Zone: ZoneType = (function(global: any) {
754
754
}
755
755
} finally {
756
756
if ( task . type == eventTask || ( task . data && task . data . isPeriodic ) ) {
757
- reEntryGuard && ( task as ZoneTask ) . _transitionTo ( scheduled , running , notScheduled ) ;
757
+ // if the task's state is notScheduled, then it has already been cancelled
758
+ // we should not reset the state to scheduled
759
+ if ( task . state !== notScheduled ) {
760
+ reEntryGuard && ( task as ZoneTask ) . _transitionTo ( scheduled , running ) ;
761
+ }
758
762
} else {
759
763
task . runCount = 0 ;
760
764
this . _updateTaskCount ( task as ZoneTask , - 1 ) ;
Original file line number Diff line number Diff line change @@ -299,6 +299,30 @@ describe('Zone', function() {
299
299
] ) ;
300
300
} ) ;
301
301
302
+ it ( 'period task should not transit to scheduled state after being cancelled in running state' ,
303
+ ( ) => {
304
+ const zone = Zone . current . fork ( { name : 'testZone' } ) ;
305
+
306
+ const task = zone . scheduleMacroTask ( 'testPeriodTask' , ( ) => {
307
+ zone . cancelTask ( task ) ;
308
+ } , { isPeriodic : true } , ( ) => { } , ( ) => { } ) ;
309
+
310
+ task . invoke ( ) ;
311
+ expect ( task . state ) . toBe ( 'notScheduled' ) ;
312
+ } ) ;
313
+
314
+ it ( 'event task should not transit to scheduled state after being cancelled in running state' ,
315
+ ( ) => {
316
+ const zone = Zone . current . fork ( { name : 'testZone' } ) ;
317
+
318
+ const task = zone . scheduleEventTask ( 'testEventTask' , ( ) => {
319
+ zone . cancelTask ( task ) ;
320
+ } , null , ( ) => { } , ( ) => { } ) ;
321
+
322
+ task . invoke ( ) ;
323
+ expect ( task . state ) . toBe ( 'notScheduled' ) ;
324
+ } ) ;
325
+
302
326
describe ( 'assert ZoneAwarePromise' , ( ) => {
303
327
it ( 'should not throw when all is OK' , ( ) => {
304
328
Zone . assertZonePatched ( ) ;
You can’t perform that action at this time.
0 commit comments