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

Commit 80ae6a8

Browse files
hmdhkmhevery
authored andcommitted
feat: return timeout Id in ZoneTask.toString (fixes #341)
Closes #375
1 parent 597c634 commit 80ae6a8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: lib/zone.ts

+13
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ interface TaskData {
395395
* Delay in milliseconds when the Task will run.
396396
*/
397397
delay?: number;
398+
399+
/**
400+
* identifier returned by the native setTimeout.
401+
*/
402+
handleId?: number;
398403
}
399404

400405
/**
@@ -819,6 +824,14 @@ const Zone: ZoneType = (function(global: any) {
819824
}
820825
};
821826
}
827+
828+
public toString() {
829+
if (this.data && typeof this.data.handleId !== 'undefined') {
830+
return this.data.handleId;
831+
} else {
832+
return this.toString();
833+
}
834+
}
822835
}
823836

824837
interface UncaughtPromiseError extends Error {

Diff for: test/common/setTimeout.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ describe('setTimeout', function () {
8888
});
8989
});
9090

91+
it('should return the timeout Id through toString', function () {
92+
var cancelId = setTimeout(() => {
93+
}, 0);
94+
expect(typeof (cancelId.toString())).toBe('number');
95+
})
96+
9197
it('should pass invalid values through', function () {
9298
clearTimeout(null);
9399
clearTimeout(<any>{});

0 commit comments

Comments
 (0)