-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add timeout * feat: add scan time
- Loading branch information
1 parent
d3eaa6a
commit aee6813
Showing
7 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const moment = require('moment'); | ||
|
||
export default class Timer { | ||
protected startTime: number; | ||
protected endTime: undefined | number; | ||
|
||
constructor(timeout?: number) { | ||
this.startTime = Date.now(); | ||
if (timeout) { | ||
this.endTime = this.startTime + timeout; | ||
} | ||
} | ||
|
||
public checkTimeout(): void { | ||
if (this.endTime && Date.now() > this.endTime) { | ||
throw new Error('@iceworks/doctor time out!'); | ||
} | ||
} | ||
|
||
public duration(): number { | ||
return moment.duration(Date.now() - this.startTime).asSeconds(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters