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

Commit

Permalink
feat: return timeout Id in ZoneTask.toString (fixes #341)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdhk committed Jul 12, 2016
1 parent ed69756 commit 3fd578b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/zone.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ interface TaskData {
* Delay in milliseconds when the Task will run.
*/
delay?: number;
/**
* identifier returned by the native setTimeout.
*/
handleId?: number;
}
/**
* Represents work which is executed with a clean stack.
Expand Down
13 changes: 13 additions & 0 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ interface TaskData {
* Delay in milliseconds when the Task will run.
*/
delay?: number;

/**
* identifier returned by the native setTimeout.
*/
handleId?: number;
}

/**
Expand Down Expand Up @@ -819,6 +824,14 @@ const Zone: ZoneType = (function(global: any) {
}
};
}

public toString() {
if (this.data && typeof this.data.handleId !== 'undefined') {
return this.data.handleId;
} else {
return this.toString();
}
}
}

interface UncaughtPromiseError extends Error {
Expand Down
6 changes: 6 additions & 0 deletions test/common/setTimeout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ describe('setTimeout', function () {
});
});

it('should return the timeout Id through toString', function () {
var cancelId = setTimeout(() => {
}, 0);
expect(typeof cancelId.toString()).toBe('number');
})

it('should pass invalid values through', function () {
clearTimeout(null);
clearTimeout(<any>{});
Expand Down

0 comments on commit 3fd578b

Please sign in to comment.