Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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