Comparing version 0.1.5 to 1.0.0
{ | ||
"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(); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17261
0
10
463
1
105
3
1
- Removedbluebird@^3.4.6
- Removedbluebird@3.7.2(transitive)