deno_std
deno_std copied to clipboard
WIP chore(log): migrate std/log to use the Web Streams API
Tackling this issue: https://github.com/denoland/deno_std/issues/3907
Whats left to do in this PR:
- [x] Tests need updating
- [x] Race conditions need handling and testing
- [ ] Figure out how destroy is handled by callers now that its async
- [x] Understand how to "unload" works with promises and if we need to do something about the destroy handler
- It does not wait for promises to resolve, this is potentially a big problem as this means we will always lose the last write when the flush is async.
- [ ] Should new properties use protected or #hashName
- [ ] Delete PR specific comments
- [ ] Understand why double dispatch exists on the "Window unload flushes buffer" test
- [x] Support multiple calls to destroy.
- [ ] Remove delay(1) from "Window unload flushes buffer", detect when unload handler is finished
- [ ] Remove delay(1) from "FileHandler: Critical logs trigger immediate flush", detect when unload handler is finished
- [ ] Either un-export LogQueue or move it to std/async/???.ts
- [ ] Write more tests
Initial Idea:
- Replacing BufWriterSync with Buffer from std/streams/buffer.ts
- Using the magic line
this._buf.readable.pipeTo(this._file.writable);to pipe the buffer to the file once full. - Change as little as possible
I'm not sure how much time I can dedicate to this over the next few weeks so if anyone wants to pick this up, you are welcome to.
Due to the fact that the unload lifecycle event handler does not await promises, using the async streams API is very risky as the last flush on unload would not complete.
As an alternative I've created this new PR https://github.com/denoland/deno_std/pull/4021 that keeps to synchronous functions. It removes all std/io and Deno.Writer references and uses a plain ArrayBuffer and Uint8Array to buffer logs. Also it's a very small diff compared to this PR, only +22 −13.
Closing in favour of #4021.