- Source:
Factory responsible for creating, validating and destroying the objects used by the pool
Example
const Api = require('some-api');
const factory = {
create: async () => {
const api = new Api();
await api.connect();
return api;
},
destroy: async api => {
await api.disconnect();
console.log(`${api} has been disconnected!`);
},
validate: async api => {
const response = await api.ping()
const isValid = (response && response.time < 100)
return isValid
}
Methods
create() → {Promise.<T>}
- Source:
Returns:
Promise of factory object
- Type
- Promise.<T>
destroy(object) → {Promise.<void>}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
object |
T |
Returns:
- Type
- Promise.<void>
validate(object) → {Promise.<boolean>}
- Source:
Should return true
if item is valid, else false
Parameters:
Name | Type | Description |
---|---|---|
object |
T |
Returns:
Promise with validation result
- Type
- Promise.<boolean>