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.0.0 to 1.1.0

6

CHANGES.md
# promise-timeout
## v1.1.0 (2017-03-07)
* Updated mocha.
* #1 - Clear timeout when promise settles, to avoid issues blocking the
event loop from exiting.
## v1.0.0 (2015-11-18)
* Initial release

16

index.js

@@ -1,2 +0,2 @@

// Copyright (c) 2015 David M. Lee, II
// Copyright (c) 2015-2017 David M. Lee, II
'use strict';

@@ -23,10 +23,18 @@

module.exports.timeout = function(promise, timeoutMillis) {
let timeout;
return Promise.race([
promise,
new Promise(function(resolve, reject) {
setTimeout(function() {
timeout = setTimeout(function() {
reject(new TimeoutError());
}, timeoutMillis);
})
]);
}),
]).then(function(v) {
clearTimeout(timeout);
return v;
}, function(err) {
clearTimeout(timeout);
throw err;
});
};
{
"name": "promise-timeout",
"version": "1.0.0",
"version": "1.1.0",
"description": "Simple timeouts for promises",

@@ -9,8 +9,15 @@ "main": "index.js",

},
"keywords": ["promise", "timeout"],
"keywords": [
"promise",
"timeout"
],
"author": "David M. Lee, II <leedm777@yahoo.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/building5/promise-timeout.git"
},
"devDependencies": {
"mocha": "^2.3.4"
"mocha": "^3.2.0"
}
}

@@ -26,5 +26,6 @@ // Copyright (c) 2015 David M. Lee, II

describe('a fast promise', function() {
it('should resolve', function() {
return pt.timeout(later(10), 1000)
.then(function() {
it('should resolve with correct value', function() {
return pt.timeout(Promise.resolve('some value'), 1000)
.then(function(val) {
assert.equal(val, 'some value');
}, function(err) {

@@ -34,3 +35,11 @@ assert.fail('should have resolved');

});
it('should reject with correct exception', function() {
return pt.timeout(Promise.reject(new Error('some error')), 1000)
.then(function(val) {
assert.fail('should have rejected');
}, function(err) {
assert.equal(err.message, 'some error');
});
});
});
});
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