service-pool
Advanced tools
Comparing version 0.0.5 to 1.0.0
'use strict' | ||
const constants = { | ||
module.exports = { | ||
MAX_POOL_SIZE: 0 | ||
} | ||
module.exports = constants |
'use strict' | ||
let constants = { | ||
module.exports = { | ||
ARRAY: 'Array', | ||
@@ -32,3 +32,1 @@ ARRAY_BUFFER: 'ArrayBuffer', | ||
} | ||
module.exports = constants |
'use strict' | ||
const typeDetect = require('type-detect') | ||
const TypeDetect = require('type-detect') | ||
const Enums = require('./Enums') | ||
@@ -11,3 +11,3 @@ const EnumsTypeDetect = require('./EnumsTypeDetect') | ||
this.max = typeDetect(config.max) === EnumsTypeDetect.NUMBER ? config.max : Enums.MAX_POOL_SIZE | ||
this.max = TypeDetect(config.max) === EnumsTypeDetect.NUMBER ? config.max : Enums.MAX_POOL_SIZE | ||
this.pool = {} | ||
@@ -25,8 +25,4 @@ } | ||
getActiveIds () { | ||
let result = [] | ||
for (let x in this.pool) { | ||
result.push(x) | ||
} | ||
const result = [] | ||
for (const x in this.pool) result.push(x) | ||
return result | ||
@@ -36,7 +32,4 @@ } | ||
reset () { | ||
for (let x in this.pool) { | ||
if(this.pool[x].destroy) { | ||
this.pool[x].destroy(this.pool[x].service) | ||
} | ||
for (const x in this.pool) { | ||
if (this.pool[x].destroy) this.pool[x].destroy(this.pool[x].service) | ||
delete this.pool[x] | ||
@@ -48,9 +41,9 @@ } | ||
async add (entry) { | ||
add (entry) { | ||
let length = 0 | ||
let msg = null; | ||
let msg = null | ||
return new Promise((resolve, reject) => { | ||
// Validate entry object returned | ||
if (typeDetect(entry) !== EnumsTypeDetect.OBJECT) { | ||
if (TypeDetect(entry) !== EnumsTypeDetect.OBJECT) { | ||
msg = 'Invalid JS Object passed as parameter' | ||
@@ -61,20 +54,9 @@ } else if (!entry.onAdd) { | ||
if(msg) { | ||
reject(msg) | ||
} | ||
if (msg) reject(msg) | ||
for (const x in this.pool) if (x === entry.id) this.destroy(x) | ||
for (let x in this.pool) { | ||
if (x === entry.id) { | ||
// Destroy current service | ||
this.destroy(x) | ||
} | ||
} | ||
// If max is reached remove last service | ||
length = Object.keys(this.pool).length | ||
if ((this.max > 0) && (length >= this.max)) this.destroy(Object.keys(this.pool)[0]) | ||
if ((this.max > 0) && (length >= this.max)) { | ||
this.destroy(Object.keys(this.pool)[0]) | ||
} | ||
// Add new Service | ||
@@ -92,30 +74,21 @@ this.pool[entry.id] = { | ||
get (id) { | ||
if (this.pool[id]) { | ||
return this.pool[id].service | ||
} else { | ||
return null | ||
} | ||
return this.pool[id] ? this.pool[id].service : null | ||
} | ||
test (id) { | ||
if (this.pool[id]) { | ||
if (this.pool[id].test) { | ||
return this.pool[id].test(this.pool[id].service) | ||
} | ||
} | ||
return null | ||
let result = null | ||
if (this.pool[id] && this.pool[id].test) result = this.pool[id].test(this.pool[id].service) | ||
return result | ||
} | ||
destroy (id) { | ||
let result = null | ||
if (this.pool[id]) { | ||
if (this.pool[id].destroy) { | ||
this.pool[id].destroy(this.pool[id].service) | ||
} | ||
if (this.pool[id].destroy) this.pool[id].destroy(this.pool[id].service) | ||
delete this.pool[id] | ||
return true | ||
result = true | ||
} | ||
return null | ||
return result | ||
} | ||
@@ -122,0 +95,0 @@ } |
{ | ||
"name": "service-pool", | ||
"license": "MIT", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"description": "A simple, lightweight, Resource Pool Manager for NodeJS", | ||
@@ -23,2 +23,6 @@ "homepage": "https://agilite.io", | ||
], | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"keywords": [ | ||
@@ -28,17 +32,15 @@ "agilit-e", | ||
"pool", | ||
"pooling" | ||
"pooling", | ||
"service-pool", | ||
"generic-pool" | ||
], | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"dotenv": "8.0.0", | ||
"dotenv": "8.2.0", | ||
"type-detect": "4.0.8" | ||
}, | ||
"devDependencies": { | ||
"mongoose": "5.6.4", | ||
"mongoose": "5.9.24", | ||
"chai": "4.2.0", | ||
"mocha": "6.1.4" | ||
"mocha": "8.0.1" | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
10758
230
+ Addeddotenv@8.2.0(transitive)
- Removeddotenv@8.0.0(transitive)
Updateddotenv@8.2.0