Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generic-pool

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-pool - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

lib/Deque.js

6

CHANGELOG.md
# Change Log
## [3.1.0] - November 6 2016
- Inject dependencies into Pool to allow easier user extension
## [3.0.1] - November 1 2016

@@ -126,3 +129,4 @@ - Passthrough Pool's promise impl to deferreds so they are used internally and exposed correctly on pool.acquire (@eide)

=======
[unreleased]: https://github.com/coopernurse/node-pool/compare/v3.0.1...HEAD
[unreleased]: https://github.com/coopernurse/node-pool/compare/v3.1.0...HEAD
[3.1.0]: https://github.com/coopernurse/node-pool/compare/v3.0.1...v3.1.0
[3.0.1]: https://github.com/coopernurse/node-pool/compare/v3.0.0...v3.0.1

@@ -129,0 +133,0 @@ [3.0.0]: https://github.com/coopernurse/node-pool/compare/v2.4.3...v3.0.0

16

index.js
const Pool = require('./lib/Pool')
exports.Pool = Pool
exports.createPool = function(factory, config){
return new Pool(factory, config)
const Deque = require('./lib/Deque')
const PriorityQueue = require('./lib/PriorityQueue')
const DefaultEvictor = require('./lib/DefaultEvictor')
module.exports = {
Pool: Pool,
Deque: Deque,
PriorityQueue: PriorityQueue,
DefaultEvictor: DefaultEvictor,
createPool: function(factory, config){
return new Pool(DefaultEvictor, Deque, PriorityQueue, factory, config)
}
}

@@ -7,8 +7,5 @@ 'use strict'

const PoolOptions = require('./PoolOptions')
const PriorityQueue = require('./PriorityQueue')
const ResourceRequest = require('./ResourceRequest')
const ResourceLoan = require('./ResourceLoan')
const PooledResource = require('./PooledResource')
const DLLArray = require('./DLLArray')
const DefaultEvictor = require('./DefaultEvictor')

@@ -38,3 +35,3 @@ /**

*/
constructor (factory, options) {
constructor (Evictor, Deque, PriorityQueue, factory, options) {
super()

@@ -75,3 +72,3 @@

*/
this._availableObjects = new DLLArray()
this._availableObjects = new Deque()

@@ -114,3 +111,3 @@ /**

this._evictor = new DefaultEvictor()
this._evictor = new Evictor()

@@ -117,0 +114,0 @@ /**

@@ -28,3 +28,2 @@ 'use strict'

enqueue (obj, priority) {
let priorityOrig
// Convert to integer with a default value of 0.

@@ -34,11 +33,8 @@ priority = priority && +priority | 0 || 0

if (priority) {
priorityOrig = priority
if (priority < 0 || priority >= this._size) {
priority = (this._size - 1)
// put obj at the end of the line
// FIXME: remove this logging
console.trace('invalid priority: ' + priorityOrig + ' must be between 0 and ' + priority)
}
}
this._slots[priority].add(obj)
this._slots[priority].push(obj)
}

@@ -49,3 +45,3 @@

if (this._slots[i].length) {
return this._slots[i].remove()
return this._slots[i].shift()
}

@@ -52,0 +48,0 @@ }

'use strict'
const DoublyLinkedList = require('./DoublyLinkedList')
const Deque = require('./Deque')

@@ -12,62 +13,15 @@ /**

*/
class Queue {
constructor () {
this._list = new DoublyLinkedList()
}
get length () {
return this._list.length
}
class Queue extends Deque {
/**
* Adds the obj to the end of the list for this slot
* we completely override the parent method because we need access to the
* node for our rejection handler
* @param {[type]} item [description]
*/
add (resourceRequest) {
push (resourceRequest) {
const node = DoublyLinkedList.createNode(resourceRequest)
resourceRequest.promise.catch(this._createTimeoutRejectionHandler(node))
this._list.insertEnd(node)
}
/**
* Removes and returns the obj at the head of the list for this slot
* @return {ResourceRequest} [description]
*/
remove () {
if (this._list.length === 0) {
return undefined
}
const node = this._list.head
this._list.remove(node)
return node.data
}
/**
* get a reference to the item at the head of the queue
* @return {ResourceRequest} [description]
*/
get head () {
if (this._list.length === 0) {
return undefined
}
const node = this._list.head
return node.data
}
/**
* get a reference to the item at the tail of the queue
* @return {ResourceRequest} [description]
*/
get tail () {
if (this._list.length === 0) {
return undefined
}
const node = this._list.tail
return node.data
}
_createTimeoutRejectionHandler (node) {

@@ -74,0 +28,0 @@ return (reason) => {

{
"name": "generic-pool",
"description": "Generic resource pooling for Node.JS",
"version": "3.0.1",
"version": "3.1.0",
"author": "James Cooper <james@bitmechanic.com>",

@@ -6,0 +6,0 @@ "contributors": [

@@ -1,6 +0,8 @@

var tap = require('tap')
var Pool = require('../lib/Pool')
'use strict'
const tap = require('tap')
const createPool = require('../').createPool
tap.test('acquireTimeout handles timed out acquire calls', function (t) {
var factory = {
const factory = {
create: function () {

@@ -15,3 +17,3 @@ return new Promise(function (resolve) {

}
var config = {
const config = {
acquireTimeoutMillis: 20,

@@ -22,3 +24,3 @@ idleTimeoutMillis: 150,

var pool = new Pool(factory, config)
const pool = createPool(factory, config)

@@ -43,4 +45,4 @@ pool.acquire()

tap.test('acquireTimeout handles non timed out acquire calls', function (t) {
var myResource = {}
var factory = {
const myResource = {}
const factory = {
create: function () {

@@ -56,7 +58,7 @@ return new Promise(function (resolve) {

var config = {
const config = {
acquireTimeoutMillis: 400
}
var pool = new Pool(factory, config)
const pool = createPool(factory, config)

@@ -63,0 +65,0 @@ pool.acquire()

'use strict'
const tap = require('tap')
const Pool = require('../lib/Pool')
const createPool = require('../').createPool
const utils = require('./utils')

@@ -15,3 +15,3 @@ const ResourceFactory = utils.ResourceFactory

// const pool = new Pool(resourceFactory, config)
// const pool = createPool(resourceFactory, config)

@@ -44,3 +44,3 @@ // // NOTES:

// const pool = new Pool(resourceFactory, config)
// const pool = createPool(resourceFactory, config)

@@ -59,3 +59,3 @@ // // FIXME: this logic only works because we know it takes ~1ms to create a resource

const pool = new Pool(resourceFactory)
const pool = createPool(resourceFactory)

@@ -75,3 +75,3 @@ t.equal(1, pool.max)

}
const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -91,3 +91,3 @@ t.equal(1, pool.max)

}
const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -113,3 +113,3 @@ t.equal(3, pool.max)

const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -161,3 +161,3 @@ function lowPriorityOnFulfilled (obj) {

// const pool = new Pool(resourceFactory, config)
// const pool = createPool(resourceFactory, config)

@@ -197,3 +197,3 @@ // const op1 = pool.acquire()

}
const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -222,3 +222,3 @@ setTimeout(function () {

}
const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -281,3 +281,3 @@ const operations = []

const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -331,3 +331,3 @@ // FIXME: this section no longer proves anything as factory

const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -364,3 +364,3 @@ let errorCount = 0

const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -414,3 +414,3 @@ const borrowedResources = []

const pool = new Pool(resourceFactory, config)
const pool = createPool(resourceFactory, config)

@@ -477,3 +477,3 @@ const borrowedResources = []

// const pool = new Pool(factory, config)
// const pool = createPool(factory, config)

@@ -513,3 +513,3 @@ // pool.acquire().then(function (obj) {

// const pool = new Pool(factory, config)
// const pool = createPool(factory, config)

@@ -557,3 +557,3 @@ // pool.acquire()

const pool = new Pool(factory, config)
const pool = createPool(factory, config)
// pool.acquire(function () {})

@@ -569,3 +569,3 @@ pool.acquire().then(function (obj) {

tap.test('returns only valid object to the pool', function (t) {
const pool = new Pool({
const pool = createPool({
create: function () {

@@ -597,3 +597,3 @@ return Promise.resolve({ id: 'validId' })

tap.test('validate acquires object from the pool', function (t) {
const pool = new Pool({
const pool = createPool({
create: function () {

@@ -600,0 +600,0 @@ return Promise.resolve({ id: 'validId' })

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