['get', 'set'].forEach( k => { redisClient[`${k}Async`] = promisify(redisClient[k]); } );
function checkMetricsPermission (cb) { /* istanbul ignore if: tracking intentionally disabled when running tests */ if (insight.optOut === undefined) { return promisify(insight.askPermission).call( insight, 'May Clinic.js report anonymous usage statistics to improve the tool over time?' ) } return Promise.resolve() }
async close() { if (this.wsServer) { const close = util.promisify(this.wsServer.close.bind(this.wsServer)); await close(); } if (this.subscriptionsTimer) { clearInterval(this.subscriptionsTimer); } }
async executeStatement(conn, query, cancelObj) { const createStatementAsync = promisify(conn.createStatement.bind(conn)); const statement = await createStatementAsync(); if (cancelObj) { cancelObj.cancel = promisify(statement.cancel.bind(statement)); } const setQueryTimeout = promisify(statement.setQueryTimeout.bind(statement)); await setQueryTimeout(600); const executeQueryAsync = promisify(statement.execute.bind(statement)); const resultSet = await executeQueryAsync(query); const toObjArrayAsync = resultSet.toObjArray && promisify(resultSet.toObjArray.bind(resultSet)) || (() => Promise.resolve(resultSet)); return await toObjArrayAsync(); }
this.jdbcProps = this.getJdbcProperties(); const getConnection = promisify(DriverManager.getConnection.bind(DriverManager)); return new Connection(await getConnection(this.config.url, this.jdbcProps)); }, destroy: async (connection) => { return promisify(connection.close.bind(connection)); }, validate: (connection) => { const isValid = promisify(connection.isValid.bind(connection)); try { return isValid(this.testConnectionTimeout() / 1000);
router.get('/installed', async (req) => { const offset = req.query.offset ? Number(req.query.offset) : 0 const limit = req.query.limit ? Number(req.query.limit) : 20 const installedIds = await promisify(modules.chains.getInstalledIds).call() if (installedIds.length === 0) return { count: 0, chains: [] } const condition = { name: { $in: installedIds } } const count = await app.sdb.count('Chain', condition) const chains = await app.sdb.findAll('Chain', { condition, limit, offset }) return { count, chains } })
const getCheckClasses = async () => { const checkNames = await util.promisify(fs.readdir)(path.join(__dirname, 'checks')); const checks = checkNames.reduce((result, filePath) => { const _class = require(path.join(__dirname, 'checks', filePath)); result[_class.type || filePath] = _class; return result; }, {}); return Object.assign(checks, CHECKS); }
// Start an HTTP server to mock API calls (telemetry server and Bitballoon) // Tests are using child processes, so we cannot use `nock` or similar library // that relies on monkey-patching global variables. const startServer = async function(path, response = {}, { status = 200 } = {}) { const requests = [] const server = createServer((req, res) => requestHandler({ req, res, requests, response, status, path })) await promisify(server.listen.bind(server))(0) const host = getHost(server) const stopServer = promisify(server.close.bind(server)) return { scheme: 'http', host, requests, stopServer } }
// Start an UDP server to mock calls. const startUdpServer = async function() { const requests = [] const server = createSocket('udp4', buffer => { requests.push(buffer.toString()) }) await promisify(server.bind.bind(server))(0) const { address, port } = server.address() const stopServer = promisify(server.close.bind(server)) return { host: address, port, requests, stopServer } }
function writeToJson (filePath, json) { const options = { encoding: 'utf-8' } return promisify(fs.writeFile)(filePath, JSON.stringify(json), options) }
const reportError = async function({ errorMonitor, error, logs, testOpts, eventProps }) { if (testOpts.errorMonitor) { printEventForTest(error, eventProps, logs) return } try { await promisify(errorMonitor.notify)(error, event => onError(event, eventProps)) // Failsafe } catch (error) { log(logs, `Error monitor could not notify\n${error.stack}`) return } }
const getAdapters = async () => { const adapterNames = await util.promisify(fs.readdir)(path.join(__dirname, 'adapters')); const adapters = adapterNames.reduce((result, filePath) => { result[path.basename(filePath, path.extname(filePath))] = require(path.join(__dirname, 'adapters', filePath)); return result; }, {}); return Object.assign(adapters, ADAPTERS); }
[ 'brpop', 'del', 'get', 'hget', 'rpop', 'set', 'zadd', 'zrange', 'zrangebyscore', 'keys', 'watch', 'unwatch', 'incr', 'decr', 'lpush' ].forEach( k => { client[`${k}Async`] = promisify(client[k]); } );