diff options
author | EuAndreh <eu@euandre.org> | 2024-03-06 12:19:42 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-06 12:19:42 -0300 |
commit | d866862275d2d131db47cc0ed767ac2df0661a2d (patch) | |
tree | 6c924620ba49531dcfd28d12d0770619ec393d37 | |
parent | src/hero.mjs: Add makeLineEmitter() (diff) | |
download | papod-d866862275d2d131db47cc0ed767ac2df0661a2d.tar.gz papod-d866862275d2d131db47cc0ed767ac2df0661a2d.tar.xz |
src/hero.mjs: Add skeleton for makePipeReaderFn()
-rw-r--r-- | src/hero.mjs | 25 | ||||
-rw-r--r-- | tests/js/hero.mjs | 20 |
2 files changed, 40 insertions, 5 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 8cbbe36..0a086ad 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -357,6 +357,17 @@ export const makeLineEmitter = fn => { }; }; +export const makePipeReaderFn = ({ + lineFn, +} = { + lineFn: lineHandler +}) => path => { + mkfifo(path); + // TODO +}; + +export const makePipeReader = makePipeReaderFn(); + export const buildRoutes = (routes, globalInterceptors = []) => routes.reduce( (acc, [methods, path, handlerFn, interceptors = []]) => @@ -374,12 +385,16 @@ export const buildRoutes = (routes, globalInterceptors = []) => export const promisifyServer = (name, serverHandle) => ({ ref: serverHandle, - listen: util.promisify((udsPath, ...args) => { + listen: util.promisify((socket, pipe, ...args) => { + assert.equal(typeof socket, "string"); + assert.equal(typeof pipe, "string"); configLogger({ name }); - if (fs.existsSync(udsPath)) { - fs.unlinkSync(udsPath); - } - return serverHandle.listen(udsPath, ...args) + + rmIf(pipe); + makePipeReader(pipe); + + rmIf(socket); + return serverHandle.listen(socket, ...args) }), close: util.promisify((...args) => serverHandle.close(...args)), events: serverHandle, diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 1debdc5..d4c6b57 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -33,6 +33,7 @@ import { rmIf, mkfifo, makeLineEmitter, + makePipeReaderFn, buildRoutes, promisifyServer, buildServer, @@ -1369,6 +1370,24 @@ const test_makeLineEmitter = async t => { }); }; +const test_makePipeReaderFn = async t => { + t.start("makePipeReaderFn()"); + + await t.test("we can close it manually with no data", async () => { + const path = "tests/hero-2.pipe"; + const lines = []; + const lineFn = x => lines.push(x); + const makePipeReader = makePipeReaderFn({ lineFn: null }); + }); + + await t.test("closing on pipe EOF reopens", async () => { + const path = "tests/hero-3.pipe"; + const lines = []; + const lineFn = x => lines.push(x); + const makePipeReader = makePipeReaderFn({ lineFn }); + }); +}; + const test_buildRoutes = async t => { t.start("buildRoutes()"); @@ -1604,6 +1623,7 @@ await runner.runTests([ test_rmIf, test_mkfifo, test_makeLineEmitter, + test_makePipeReaderFn, test_promisifyServer, test_buildServer, ]); |