service-pool
A simple, lightweight, Resource Pool Manager for NodeJS
Created by Agilit-e
About
Inspired by generic-pool, service-pool aims to provide a simple means of managing service connections of any kind via a pool resource and accessing these services using a unique identifier.
Installation
$ npm install service-pool [--save]
Example
The below example shows how to setup a Service Pool with maximum 2 connections to a local MongoDB environment. It's similar to generic-pool, but take note of the 'id' property as well as the ability to test the service connection.
const mongoose = require('mongoose')
const servicePool = require("service-pool");
const config = { max: 2 }
const pool = new servicePool(config)
const id = 'unique-id-value'
const serviceEntry = {
id,
onAdd: function () {
const url = 'mongodb://localhost/dbname'
return mongoose.createConnection(url)
},
onTest: function (service) {
return service.readyState === 1
},
onDestroy: function (service) {
return service.close()
}
}
pool.add(serviceEntry, (err, service) => {
})
let service = pool.get(id)
let serviceActive = pool.test(id)
let isDestroyed = pool.destroy(id)
let isReset = pool.reset()
Run Tests
$ npm install
$ npm test
License
MIT License
Copyright (c) 2019 Agilit-e