@electric-sql/d2mini
Version:
D2Mini is a minimal implementation of Differential Dataflow for performing in-memory incremental view maintenance.
32 lines • 1.02 kB
JavaScript
import { DifferenceStreamWriter, UnaryOperator, } from '../graph.js';
import { StreamBuilder } from '../d2.js';
/**
* Operator that outputs the messages in the stream
*/
export class OutputOperator extends UnaryOperator {
#fn;
constructor(id, inputA, output, fn) {
super(id, inputA, output);
this.#fn = fn;
}
run() {
for (const message of this.inputMessages()) {
this.#fn(message);
this.output.sendData(message);
}
}
}
/**
* Outputs the messages in the stream
* @param fn - The function to call with each message
*/
export function output(fn) {
return (stream) => {
const output = new StreamBuilder(stream.graph, new DifferenceStreamWriter());
const operator = new OutputOperator(stream.graph.getNextOperatorId(), stream.connectReader(), output.writer, fn);
stream.graph.addOperator(operator);
stream.graph.addStream(output.connectReader());
return output;
};
}
//# sourceMappingURL=output.js.map