Skip to content

Commit

Permalink
add reflector promise helper
Browse files Browse the repository at this point in the history
fix some doc typos
  • Loading branch information
James Butler committed Nov 25, 2016
1 parent d973050 commit a85ba82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const ResourceRequest = require('./ResourceRequest')
const ResourceLoan = require('./ResourceLoan')
const PooledResource = require('./PooledResource')

const reflector = require('./utils').reflector

/**
* TODO: move me
*/
Expand Down Expand Up @@ -468,7 +470,7 @@ class Pool extends EventEmitter {
/**
* Disallow any new acquire calls and let the request backlog dissapate.
* Resolves once all resources are returned to pool and available...
* should ptobably be called "drain work"
* should probably be called "drain work"
* @returns {Promise}
*/
drain () {
Expand All @@ -484,17 +486,16 @@ class Pool extends EventEmitter {
if (this._waitingClientsQueue.length > 0) {
// wait for last waiting client to be settled
// FIXME: what if they can "resolve" out of order....?
return this._waitingClientsQueue.tail.promise.then(() => {}, () => {})
return reflector(this._waitingClientsQueue.tail.promise)
}
return this._Promise.resolve()
}

// FIXME: this is a horrific mess
__allResourcesReturned () {
const ps = []
this._resourceLoans.forEach(function (loan) {
ps.push(loan.promise)
})
const ps = Array.from(this._resourceLoans.values)
.map((loan) => loan.promise)
.map(reflector)
return this._Promise.all(ps)
}

Expand All @@ -510,11 +511,6 @@ class Pool extends EventEmitter {
*
*/
clear () {
const reflector = (promise) => {
const h = () => this._Promise.resolve()
return promise.then(h, h)
}

this._descheduleEvictorRun()
// wait for outstanding factory.create to complete
// FIXME: any new factory.create calls created after this will not
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

function noop () {}

/**
* Reflects a promise but does not expose any
* underlying value or rejection from that promise.
* @param {Promise} promise [description]
* @return {Promise} [description]
*/
exports.reflector = function (promise) {
return promise.then(noop, noop)
}

0 comments on commit a85ba82

Please sign in to comment.