Skip to content

Commit 51fb7db

Browse files
cody-greenebrianc
authored andcommitted
Support function-like construction (plus test) (brianc#23)
* Support function-like construction Remove the necessity of using `new` in front of the `Pool`, i.e. allow it to be used as a regular function. This is following brianc#1077 * add Pool factory test
1 parent 1d89029 commit 51fb7db

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ var EventEmitter = require('events').EventEmitter
44
var objectAssign = require('object-assign')
55

66
var Pool = module.exports = function (options, Client) {
7+
if (!(this instanceof Pool)) {
8+
return new Pool(options, Client)
9+
}
710
EventEmitter.call(this)
811
this.options = objectAssign({}, options)
912
this.log = this.options.log || function () { }

test/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ if (typeof global.Promise === 'undefined') {
1212
}
1313

1414
describe('pool', function () {
15+
it('can be used as a factory function', function () {
16+
var pool = Pool()
17+
expect(pool instanceof Pool).to.be.ok()
18+
expect(typeof pool.connect).to.be('function')
19+
})
20+
1521
describe('with callbacks', function () {
1622
it('works totally unconfigured', function (done) {
1723
var pool = new Pool()

0 commit comments

Comments
 (0)