-
-
Save sandfox/b68eb2d96f1a36945ab838d893a2c7d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const genericPool = require("generic-pool"); | |
const factory = { | |
create: function() { | |
return new Promise(function(resolve, reject){ | |
setTimeout(function(){ | |
reject(new Error('cannot create resource')) | |
}, 1000) | |
}) | |
}, | |
destroy: function () { return Promise.resolve() } | |
} | |
const opts = { | |
acquireTimeoutMillis: 5000 | |
} | |
const myPool = genericPool.createPool(factory, opts) | |
myPool.on('factoryCreateError', function(err){ | |
console.log('factory create error, %s',err) | |
}) | |
myPool.acquire() | |
.then(function() { | |
console.log('acquired a resource') | |
}).catch(function(err){ | |
console.log('failed to acquire resource: %s', err) | |
}) | |
.then(function(){ | |
console.log('pool stats', { | |
min: myPool.min, | |
max: myPool.max, | |
size: myPool.size, | |
available: myPool.available, | |
}) | |
}) | |
setInterval(function(){ | |
// just here to keep the event loop spinning | |
}, 5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factory create error, Error: cannot create resource | |
factory create error, Error: cannot create resource | |
factory create error, Error: cannot create resource | |
factory create error, Error: cannot create resource | |
failed to acquire resource: TimeoutError: ResourceRequest timed out | |
pool stats { min: 0, max: 1, size: 1, available: 0 } | |
factory create error, Error: cannot create resource | |
## END OF OUTPUT ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment