CartoDB-SQL-API/metro/metro.js
2020-07-22 18:29:05 +02:00

20 lines
626 B
JavaScript

'use strict';
const util = require('util');
const stream = require('stream');
const pipeline = util.promisify(stream.pipeline);
const split = require('split2');
const MetricsCollector = require('./metrics-collector');
module.exports = async function metro ({ input = process.stdin, output = process.stdout, metrics = {} } = {}) {
const metricsCollector = new MetricsCollector(metrics);
const { stream: metricsStream } = metricsCollector;
try {
await metricsCollector.start();
await pipeline(input, split(), metricsStream, output);
} finally {
await metricsCollector.stop();
}
};