Skip to content

Instantly share code, notes, and snippets.

const async = require('async');
const pg = require('pg')
// QueryConnect: (QuerySource, Callback) -> Connection
// QueryDisconnect: Connection -> Connection
// getSmartQuery : (QueryConnect, QueryDisconnect, QuerySource) -> SmartQuery
function getSmartQuery(connect, disconnect, querySource) {
let conn = null;
function connectClient(query, _connectClient) {
@Kamisama666
Kamisama666 / reduceEventEmmitter.js
Created July 30, 2019 09:55
Listens to an EventEmitter and reduces the data returned.
/*
Listens to an EventEmitter and reduces the data returned. The EventEmitter must at least three types of events:
- dataEvent: it sends the data to be reduced
- endEvent: it signals the completion of the operation
- errorEvent: it sends an error. The operation is interrupted to handle it
*/
function reduceEventEmmitter({dataEvent, endEvent, errorEvent = null}, accumulator = [], reducer, eventEmitter, cb) {
eventEmitter.on(dataEvent, function handleDataEvent(data) {
accumulator = reducer(accumulator, data);
});