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
Closes #375
  • Loading branch information
hmdhk authored and mhevery committed Aug 11, 2016
1 parent 597c634 commit 80ae6a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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 80ae6a8

Please sign in to comment.