Skip to content

Zone.js afterTask is called three times #7376

@PavelPZ

Description

@PavelPZ

doClick event of this component:

import * as core from 'angular2/core';
import {global} from 'angular2/src/facade/lang';

@core.Component({
  selector: 'my-app',
  template: '<h1 (click)="doClick()">Click</h1>'
})
export class AppComponent {

  constructor(private zone: core.NgZone) {//, private http: http.Http) {
    zone.onTurnDone.subscribe(() => console.log('onTurnDone'));
  }

  doClick() {
    global.zone.fork({
      afterTask: function () {
        console.log('After task');
      }
    }).run(() => setTimeout(() => { setTimeout(() => { }, 2000); }, 2000)); //afterTask is called three times
  }
}

produced this console log:

After task
onTurnDone
After task
onTurnDone
onTurnDone
After task
onTurnDone
onTurnDone

first "After task" is printed immediatelly
second "After task" is printed after two seconds
thirds "After task" is printed after another two seconds


I am using Flux to record x play flux actions (example of such action is "doClick"). For playing recorder actions I need to play them in sync. I try to use zone.js to recognize "action is completed".

Or is there any other possibility to use zone.js or ngZone to recognize "action completed" event?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions