![Build Status](https://travis-ci.org/Vincit/tarn.js.svg?branch=master)
Why yet another resource pool?
Tarn is focused on robustness and ability to recover from errors. Tarn has timeouts for all operations
that can fail or timeout so that you should never end up with pool full of crap. Tarn has a comprehensive
test suite and we are committed to adding tests and fixing all bugs that are found.
Tarn will always remain simple.
Install
npm install tarn
Usage:
const Tarn = require('tarn').Tarn;
const pool = new Tarn({
create: (cb) => {
cb(null, new SomeResource());
},
validate: (resource) {
return true;
},
destroy: (someResource) => {
someResource.cleanup();
},
min: 2,
max: 10,
acquireTimeoutMillis: 30000,
createTimeoutMillis: 30000,
idleTimeoutMillis: 30000,
reapIntervalMillis: 1000
});
pool.acquire().promise.then(someResource => {
return useResource(someResource);
}).then(someResource => {
pool.release(someResource);
});
pool.numUsed()
pool.numFree()
pool.numPendingAcquires()
pool.numPendingCreates()