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
syscall/js: unclear behavior of js-triggered and wrapped functions #34324
Comments
For asking questions about the language, see one of our forums: https://golang.org/wiki/Questions It is not completely clear to me whether this is a documentation bug or a question about correct usage. |
This works fine for me. The code I tested:
|
@neelance thx for the example. I found my fault: I passed a wrong additional parameter to However regarding the documentation of js.Func, I propose a small change like the following to be a bit more explicit:
Otherwise this ticket can be closed. |
Current doc:
Proposed doc:
@torbenschinke Could you please give me some more detail on the reasons for your change? Doing any blocking operation directly in the wrapped function most likely results in a "deadlock" error. For this result, "the event loop waits until the goroutine returns" sounds a bit too innocent. :) |
@neelance The facts of the current documentation are not particularly coupled with each other. Each fact is correct, but because there is no specific logical glue between them, it is difficult to me to create a sufficient mental model, which is needed to understand a specific behavior. For example, the statement that each wrapped function, which is called by JavaScript's event loop, gets executed on an extra goroutine is clear, but as long as the context is not described further, it makes it hard to understand consequences: for a gopher it is a surprise that a function can get executed on a goroutine which will block the callee, without using channels, waitgroups or mutexes. Next, the statement about blocking operations is probably also correct. But what exactly is a blocking operation? Is it only related to epoll-like I/O operations or even a tight for-loop or is it calling syscall/js APIs? Without these information, it seems very hard to anticipate the actual behavior and (expected) side effects of doing I/O (like causing deadlocks) or synchronous calls into Javascript (like stopping propagation). |
I agree that we should try to make this as easily understandable as possible. The statement about waiting for the function to return is actually a bit earlier in the documentation:
Maybe this "synchronously" is not enough. Do you have any suggestion on how we can amend this part? |
I looked through some of your CLs and the js-Transport-RoundTripper and it looks quite complex in detail, so please correct me, if I got something wrong. But here is my attempt: // add the intent: why do we want to use FuncOf? // perhaps better at the beginning of the documentation, not that readers gave up reading to early // explain the in and out arguments // now we can focus on explaining the lifecycle // explain the consequences of that lifecycle |
This is great, I like it a lot! Would you mind opening a CL or pull request for the change? |
The existing documentation is improved to be more explicit about the lifecycle and its consequences. Fixes golang#34324
Change https://golang.org/cl/197458 mentions this issue: |
The existing documentation is improved to be more explicit about the lifecycle and its consequences. Fixes golang#34324
The existing documentation is improved to be more explicit about the lifecycle and its consequences. Fixes golang#34324
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Naturally I expected that the listener to the inner div should always be called first. However looking at the documentation of js.FuncOf, I don't know what to expect:
The logic of these statements is contradictory:
What did you see instead?
I tried to use
stopPropagation
but the calling order is always wrong (outer-div first), independent of registration order. Also if a callback is always executed within a new goroutine, it sounds likestopPropagation
et. al cannot be used properly.The documentation of js.FuncOf does not help me much to understand the actual calling behavior or at least if this works as "expected".
The text was updated successfully, but these errors were encountered: