Skip to content
26 changes: 19 additions & 7 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,35 @@ function Runnable(title, fn) {
utils.inherits(Runnable, EventEmitter);

/**
* Set & get timeout `ms`.
* Get current timeout value in msecs.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
* @private
* @returns {number} current timeout threshold value
*/
/**
* @summary
* Set timeout threshold value (msecs).
*
* @description
* A string argument can use shorthand (such as "2s") and will be converted.
* If the value is `0` or exceeds `2^<sup>31</sup>`, timeouts will be disabled.
*
* @private
* @param {number|string} ms - Timeout threshold value.
* @returns {Runnable} this
* @chainable
*/
Runnable.prototype.timeout = function(ms) {
if (!arguments.length) {
return this._timeout;
}
if (typeof ms === 'string') {
ms = milliseconds(ms);
}
// see #1652 for reasoning
if (ms === 0 || ms > Math.pow(2, 31)) {
this._enableTimeouts = false;
}
if (typeof ms === 'string') {
ms = milliseconds(ms);
}
debug('timeout %d', ms);
this._timeout = ms;
if (this.timer) {
Expand Down