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

Commit 3fd578b

Browse files
committed
feat: return timeout Id in ZoneTask.toString (fixes #341)
1 parent ed69756 commit 3fd578b

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

dist/zone.js.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ interface TaskData {
372372
* Delay in milliseconds when the Task will run.
373373
*/
374374
delay?: number;
375+
/**
376+
* identifier returned by the native setTimeout.
377+
*/
378+
handleId?: number;
375379
}
376380
/**
377381
* Represents work which is executed with a clean stack.

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 {

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)