Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not reopen a new file during async writing #160

Open
zaverden opened this issue Nov 27, 2022 · 3 comments
Open

Does not reopen a new file during async writing #160

zaverden opened this issue Nov 27, 2022 · 3 comments
Labels

Comments

@zaverden
Copy link

According to the docs I can pass a new file path for reopen to continue to write into new file.

However, if I call reopen during async write it ignores new file path (https://github.com/pinojs/sonic-boom/blob/v3.2.0/index.js#L304-L308)

Code to reproduce

import { once } from "node:events";
import SonicBoom from "sonic-boom";

const startingPath = "1.log";
const newPath = "2.log";

const boom = new SonicBoom({ dest: startingPath, sync: false, append: true });

await once(boom, "ready");
console.log("file:", boom.file); // 1.log

boom.write("expect f1\n");

boom.once("write", () => {
  console.log("_writing:", boom._writing); // true
  boom.reopen(newPath);
});

await once(boom, "ready"); // emitted on reopen
console.log("file:", boom.file); //! 1.log, expected 2.log

boom.write("expect f2\n"); //! written into 1.log, expected into 2.log

workaround

- boom.reopen(newPath);
+ boom.file = newPath; 
+ boom.reopen(); 
@mcollina
Copy link
Member

mcollina commented Dec 2, 2022

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina mcollina added the bug label Dec 2, 2022
@rluvaton
Copy link
Contributor

rluvaton commented Oct 5, 2023

I'll take it :)

@rluvaton
Copy link
Contributor

rluvaton commented Oct 5, 2023

I can't find a performant way to do this without cloning data that should be in the previous file

if you want to make sure that until you call reopen all pending writes finish you can listen to drain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants