// Best-effort wake-up signal for the host-side bash task processor.
//
// The FIFO carries no meaningful payload — it's just a poke to make the
// processor poll sooner than its 3 s idle scan. So `pokeFifo` is
// non-blocking by design:
//   - O_NONBLOCK on open means we don't wedge the Node event loop when no
//     reader is attached (the previous writeFileSync would hang forever
//     in that case, surfacing as "NetworkError failed to fetch" in the UI
//     when the request never returned).
//   - All errors are swallowed; the processor will pick the task up from
//     the on-disk JSON via its idle scan even if the wake-up is lost.

const fs = require('fs');

function pokeFifo(fifoPath, taskId) {
  fs.open(fifoPath, fs.constants.O_WRONLY | fs.constants.O_NONBLOCK, (err, fd) => {
    if (err) return;
    fs.write(fd, `${taskId}\n`, () => fs.close(fd, () => {}));
  });
}

module.exports = { pokeFifo };
