Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

zone.afterTask and zone.beforeTask hook methods not working #334

Closed
sap9433 opened this issue Apr 26, 2016 · 2 comments
Closed

zone.afterTask and zone.beforeTask hook methods not working #334

sap9433 opened this issue Apr 26, 2016 · 2 comments

Comments

@sap9433
Copy link

sap9433 commented Apr 26, 2016

I'm trying to implement simple zone.afterTask and beforeTask hooks but though code ain't throwing any error , those methods are never getting called.

I searched Zone repo in github , and couldn't find any reference to these methods in the source code apart from the ones that's used in the example. counting example does use afterTask and beforeTask but I've set a debugger and saw those methods are never getting called in their example as well .

It looks like these methods have been deprecated , If not kindly let me know what I'm doing wrong.

Here's my code -

import { Component } from 'angular2/core';

@Component({
  template: `
      <div>
        <p>Basic use of Zone</p>
        <button (click)="startTask()">Start Task</button>
        <p> Time taken {{timeTaken}}</p>
      </div>
    `
})
export class HelloZone {
  timeTaken: any;

  task1(){
    for (let i = 0; i < 1e5; i++);
  }

  startTask() {
    let startTime;

    let myZone = Zone.parent.fork({
      beforeTask: function() {
        startTime = new Date();
      },
      afterTask: function() {
        this.timeTaken = new Date() - startTime;
      }
    });
    myZone.run(function(){
      this.task1();
      setTimeout(this.task1, 2000);
      this.task1();
    }.bind(this));
  }
}
@hmdhk
Copy link
Contributor

hmdhk commented Apr 26, 2016

Those methods are deprecated after v0.6.0,
But they should work for v0.5.x
here is the new api

@sap9433
Copy link
Author

sap9433 commented Apr 26, 2016

Shouldn't we remove them from Readme.md . Too confusing for a developer , as they are present in examples as well .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants