-
Notifications
You must be signed in to change notification settings - Fork 786
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
The calling order of event handlers is non-deterministic #99
Comments
+1 |
@z-rui can you share the code changes you made? I am trying to accept strings pasted from the clipboard but the characters arrived in scrambled order, and I suspect it is caused by the issue you've described here. |
Last time I tried: diff --git a/events.go b/events.go
index 177bbb4..3ff7fdd 100644
--- a/events.go
+++ b/events.go
@@ -126,7 +126,7 @@ func hookTermboxEvt() {
e := termbox.PollEvent()
for _, c := range sysEvtChs {
- go func(ch chan Event) {
+ func(ch chan Event) {
ch <- crtTermboxEvt(e)
}(c)
}
@@ -236,7 +236,7 @@ func (es *EvtStream) Loop() {
case "/sig/stoploop":
return
}
- go func(a Event) {
+ func(a Event) {
es.RLock()
defer es.RUnlock()
if pattern := es.match(a.Path); pattern != "" { |
Thank you @z-rui your patch fixed the problem for me. |
kamisdev
pushed a commit
to kamisdev/powerfulTERMINAL
that referenced
this issue
May 7, 2022
sadevn
added a commit
to sadevn/go-terminal
that referenced
this issue
Mar 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It can be seen that (in
events.go
) the event handlers are called in a separate goroutine. Therefore, there is no guarantee of the order of the handlers being called.This is especially harmful to keyboard events. Consider this situation: some characters are pasted to the terminal and so a bunch of keyboard events are generated in a short time, but the order of the corresponding handlers being called are kind of random. If the program is a text editor, the actual pasted text will be shuffled.
To fix the problem, event handlers should be called synchrously. A separate goroutine can always be created in the event handler if needed.
PS: The order of keyboard events seemed to be preserved after I changed two
go
statements (inevtKbd()
and(*EvtStream) Loop()
) to simple synchrounous function calls.The text was updated successfully, but these errors were encountered: