Socket
Socket
Sign inDemoInstall

tarn

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tarn - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

41

index.js

@@ -119,2 +119,3 @@ var Promise = require('bluebird');

Pool.prototype.check = function () {
var self = this;
var timestamp = now();

@@ -126,12 +127,10 @@ var newFree = [];

for (var i = 0, li = this.free.length; i < li; ++i) {
var free = this.free[i];
if (duration(timestamp, free.timestamp) > this.idleTimeoutMillis && numDestroyed < maxDestroy) {
this.free.forEach(function (free) {
if (duration(timestamp, free.timestamp) > self.idleTimeoutMillis && numDestroyed < maxDestroy) {
numDestroyed++;
this._destroy(free.resource);
self._destroy(free.resource);
} else {
newFree.push(free);
}
}
});

@@ -144,3 +143,3 @@ this.free = newFree;

clearInterval(this.interval);
this._stopReaping();
this.destroyed = true;

@@ -150,5 +149,15 @@

return Promise.all(this.pendingCreates.map(function (create) {
create.abort();
return create.promise.reflect();
})).then(function () {
// Wait for all the used resources to be freed.
return Promise.all(self.used.map(function (used) {
return used.freed.promise.reflect();
}));
}).then(function () {
// Abort all pending acquires.
return Promise.all(self.pendingAcquires.map(function (acquire) {
acquire.abort();
return acquire.promise.reflect();
}));
}).then(function () {
// Now we can destroy all the freed resources.

@@ -159,11 +168,4 @@ self.free.map(function (free) {

// Now we can destroy all the freed resources.
self.used.map(function (used) {
self._destroy(used.resource);
});
// And abort all pending acquires.
self.pendingAcquires.map(function (acquire) {
acquire.abort();
});
self.free = [];
self.pendingAcquires = [];
}).reflect();

@@ -258,2 +260,7 @@ };

Pool.prototype._stopReaping = function () {
clearTimeout(this.interval);
this.interval = null;
};
function FreeResource(resource) {

@@ -260,0 +267,0 @@ this.resource = resource;

{
"name": "tarn",
"version": "0.1.4",
"version": "0.1.5",
"description": "Simple and robust resource pool for node.js",

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

@@ -65,2 +65,4 @@ [![Build Status](https://travis-ci.org/Vincit/tarn.js.svg?branch=master)](https://travis-ci.org/Vincit/tarn.js)

// acquires a resource. The promise is rejected with `tarn.TimeoutError`
// after `acquireTimeoutMillis` if a resource could not be acquired.
pool.acquire().promise.then(someResource => {

@@ -67,0 +69,0 @@ return useResource(someResource);

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc