This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -754,7 +754,11 @@ const Zone: ZoneType = (function(global: any) {
754754 }
755755 } finally {
756756 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+ }
758762 } else {
759763 task . runCount = 0 ;
760764 this . _updateTaskCount ( task as ZoneTask , - 1 ) ;
Original file line number Diff line number Diff line change @@ -299,6 +299,30 @@ describe('Zone', function() {
299299 ] ) ;
300300 } ) ;
301301
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+
302326 describe ( 'assert ZoneAwarePromise' , ( ) => {
303327 it ( 'should not throw when all is OK' , ( ) => {
304328 Zone . assertZonePatched ( ) ;
You can’t perform that action at this time.
0 commit comments