-
Notifications
You must be signed in to change notification settings - Fork 267
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
Support fd_sync
for stdout/stderr writers via optional interface
#2359
Conversation
Signed-off-by: Rob Herley <[email protected]>
This seems to make sense. I'm inclined to merge, @evacchi wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this implicit public API should at least go into experimental package, not in internal. I won't accept this
OK. I actually think it makes some amount of sense. When you give it an So it's already type asserted magic, just that it only works for Also, I'm not sure how this could be done with experimental, tbh. We'd type assert If so, that gets my upvote. It's not too burdensome for clients. But it's still type asserted magic, just a little more deliberate (less accidental) from clients. |
the problem is assertion on this "internal interface" vs the os.File concrete, isn't it? we could break anytime we want |
IMO the bigger problem, which hadn't occur to me, is when you “accidentally” implement the interface. For instance, I'm not sure if I pass a OTOH, if you explicitly implement |
Thanks for the feedback y'all @ncruces It would be great to implement // io.Writer
func (w *W) Write(buf []byte) (int, error) { }
// experimentalsys.File
func (w *W) Write(buf []byte) (int, experimentalsys.Errno) { } Unless I'm misunderstanding, I don't believe there is a way today I can pass the experimental type to be used for stdout/stderr. Which might be by design today because it is... experimental 😅 I also agree that satisfying a magic internal interface for |
@robherley Would it be possible to mount the response on a file in the FS instead of using stdout? I noticed it looks like you do that for input data so maybe it makes sense for output too https://github.com/robherley/webfunc/blob/main/internal%2Fsandbox%2Fsandbox.go#L103 If it were trivial to work with stdout, then it would be nice but that interface incompatibility makes it look challenging and I don't think we have a general goal of wanting stdout to be too flexible, it's really meant to collect what would otherwise go to the terminal. FS is probably the more general abstraction you need, and otherwise we'd generally expect a host ABI I think. |
Ah, correct, you can't implement both interfaces. This would have to be a new (experimental) module configuration, which would be more work. |
Looks like this will end up being a larger change than I expected, so I'll close this out. Thanks y'all |
As far as I know, when an arbitrary
io.Writer
is passed for the module's stdout/stderr, it's not possible to hook intofd_sync
when it is called on the respective file descriptor.I've extended
writerFile
struct to attempt to call aSync
method on the inner writer interface, if it passes the type assertion.My use case is as follows:
WithStdout
, I'm passing in a wrapperhttp.ResponseWriter
.os.Stdout.Sync()
I want to invokehttp.Flusher.Flush()
on the guest.As long as the writer decides to implement this simple interface:
The host can hook into whenever the client flushes the fd.
Also, thanks for this amazing project, I've been meaning to dive into wazero ever since I saw Takeshi's talk at GopherCon '22 in person 😄