Socket
Socket
Sign inDemoInstall

promise-timeout

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

5

CHANGES.md
# promise-timeout
## v1.2.0 (2018-02-08)
* #4 - Improve the stack trace for TimeoutExceptions. Thanks, @tekwiz!
* Add JsDoc for return value. Thanks again, @tekwiz!
## v1.1.1 (2017-03-21)

@@ -4,0 +9,0 @@

31

index.js

@@ -5,12 +5,7 @@ // Copyright (c) 2015-2017 David M. Lee, II

/**
* Exception indicating that the timeout expired.
* Local reference to TimeoutError
* @private
*/
var TimeoutError = module.exports.TimeoutError = function() {
Error.call(this)
Error.captureStackTrace(this, this.constructor);
this.message = 'Timeout';
};
var TimeoutError;
require('util').inherits(TimeoutError, Error);
/**

@@ -22,5 +17,8 @@ * Rejects a promise with a {@link TimeoutError} if it does not settle within

* @param {number} timeoutMillis Number of milliseconds to wait on settling.
* @returns {Promise} Either resolves/rejects with `promise`, or rejects with
* `TimeoutError`, whichever settles first.
*/
module.exports.timeout = function(promise, timeoutMillis) {
var timeout;
var timeout = module.exports.timeout = function(promise, timeoutMillis) {
var error = new TimeoutError(),
timeout;

@@ -31,3 +29,3 @@ return Promise.race([

timeout = setTimeout(function() {
reject(new TimeoutError());
reject(error);
}, timeoutMillis);

@@ -43,1 +41,12 @@ }),

};
/**
* Exception indicating that the timeout expired.
*/
TimeoutError = module.exports.TimeoutError = function() {
Error.call(this)
Error.captureStackTrace(this, timeout);
this.message = 'Timeout';
};
require('util').inherits(TimeoutError, Error);
{
"name": "promise-timeout",
"version": "1.1.1",
"version": "1.2.0",
"description": "Simple timeouts for promises",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,4 +23,13 @@ // Copyright (c) 2015 David M. Lee, II

});
});
it('have a decent stack trace', function() {
return pt.timeout(later(1000), 10)
.then(function() {
assert.fail('should not have resolved');
}, function(err) {
assert(err.stack.includes('test.js'));
});
});
});
describe('a fast promise', function() {

@@ -27,0 +36,0 @@ it('should resolve with correct value', function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc