summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-03-06 12:14:10 -0300
committerEuAndreh <eu@euandre.org>2024-03-06 12:14:10 -0300
commitf0d33b9b21b3c739ab20d8e2b60c39694350321a (patch)
tree2a0eeeb6c3e133d43d6f94734d2ba7b642d6603a /src
parentsrc/utils.mjs: Add first(), rest(), butlast() and last() (diff)
downloadpapod-f0d33b9b21b3c739ab20d8e2b60c39694350321a.tar.gz
papod-f0d33b9b21b3c739ab20d8e2b60c39694350321a.tar.xz
src/hero.mjs: Add makeLineEmitter()
Diffstat (limited to 'src')
-rw-r--r--src/hero.mjs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hero.mjs b/src/hero.mjs
index 6b6fa77..8cbbe36 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -338,6 +338,25 @@ export const rmIf = path => {
export const mkfifo = path =>
child_process.execFileSync("mkfifo", [path]);
+export const makeLineEmitter = fn => {
+ let data = "";
+ return chunk => {
+ const segments = chunk.split("\n");
+ assert.ok(segments.length > 0);
+
+ if (segments.length === 1) {
+ data += segments[0];
+ return;
+ }
+
+ [
+ data + u.first(segments),
+ ...u.butlast(u.rest(segments)),
+ ].forEach(fn);
+ data = u.last(segments);
+ };
+};
+
export const buildRoutes = (routes, globalInterceptors = []) =>
routes.reduce(
(acc, [methods, path, handlerFn, interceptors = []]) =>