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.5 to 1.0.0

lib/PendingOperation.js

16

package.json
{
"name": "tarn",
"version": "0.1.5",
"version": "1.0.0",
"description": "Simple and robust resource pool for node.js",
"main": "index.js",
"main": "lib/tarn.js",
"license": "MIT",

@@ -20,2 +20,5 @@ "scripts": {

},
"engines": {
"node": ">=6.0.0"
},
"keywords": [

@@ -29,11 +32,10 @@ "pool",

"LICENSE",
"index.js"
"lib/*"
],
"devDependencies": {
"bluebird": "^3.5.1",
"expect.js": "^0.3.1",
"mocha": "^3.0.2"
"mocha": "^4.1.0"
},
"dependencies": {
"bluebird": "^3.4.6"
}
"dependencies": {}
}

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

## Usage:
## Usage
```js
const Tarn = require('tarn').Tarn;
const { Pool, TimeoutError } = require('tarn');
const pool = new Tarn({
const pool = new Pool({

@@ -31,3 +31,3 @@ // function that creates a resource. You can either pass the resource

},
// validates a connection before it is used. Return true or false

@@ -39,3 +39,3 @@ // from it. If false is returned, the resource is destroyed and a

},
// function that destroys a resource. This is always synchronous

@@ -46,22 +46,25 @@ // as nothing waits for the return value.

},
// minimum size
min: 2,
// maximum size
max: 10,
// acquire promises are rejected after this many milliseconds
// if a resource cannot be acquired
acquireTimeoutMillis: 30000,
// create operations are cancelled after this many milliseconds
// if a resource cannot be acquired
createTimeoutMillis: 30000,
// free resouces are destroyed after this many milliseconds
idleTimeoutMillis: 30000,
// how often to check for idle resources to destroy
reapIntervalMillis: 1000
reapIntervalMillis: 1000,
// long long to idle after failed create before trying again
createRetryIntervalMillis: 200
});

@@ -71,8 +74,21 @@

// after `acquireTimeoutMillis` if a resource could not be acquired.
pool.acquire().promise.then(someResource => {
return useResource(someResource);
}).then(someResource => {
pool.release(someResource);
});
const acquire = pool.acquire();
// acquire can be aborted using the abort method
acquire.abort();
// the acquire object has a promise property that gets reolved with
// the acquired resource
try {
const resource = await acquire.promise;
} catch (err) {
// if the acquire times out an error of class TimeoutError is thrown
if (err instanceof TimeoutError) {
console.log('timeout');
}
}
// releases the resource.
pool.release(resource);
// returns the number of non-free resources

@@ -92,5 +108,3 @@ pool.numUsed()

// pool cannot be used after this.
poo.destroy().then(() => {
console.log('pool destroyed');
});
await pool.destroy();
```
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