summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-18 10:53:15 -0500
committerPietro Gagliardi <[email protected]>2014-02-18 10:53:15 -0500
commit23f6a07c7f82f9107554c5a5e228d3364652ef3e (patch)
tree47a3e52349613d47fd461b59e69916f9ee2f7b12
parent1f08c874e0c9df9019e994098e1d006a7011e533 (diff)
Buffered the event channels, as per skelterjohn's suggestion; I thought this would fix the faults I now get, but it doesn't...
-rw-r--r--button.go2
-rw-r--r--main.go2
-rw-r--r--sysdata.go9
3 files changed, 10 insertions, 3 deletions
diff --git a/button.go b/button.go
index d1b286c..39c2da1 100644
--- a/button.go
+++ b/button.go
@@ -21,7 +21,7 @@ func NewButton(text string) (b *Button) {
return &Button{
sysData: mksysdata(c_button),
initText: text,
- Clicked: make(chan struct{}),
+ Clicked: Event(),
}
}
diff --git a/main.go b/main.go
index fb79bfb..10add2d 100644
--- a/main.go
+++ b/main.go
@@ -7,7 +7,7 @@ import (
func main() {
w := NewWindow("Main Window", 320, 240)
- w.Closing = make(chan struct{})
+ w.Closing = Event()
b := NewButton("Click Me")
b2 := NewButton("Or Me")
s2 := NewStack(Horizontal, b, b2)
diff --git a/sysdata.go b/sysdata.go
index da94766..5a3f0ab 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -5,6 +5,13 @@ import (
"runtime"
)
+const eventbufsiz = 100 // suggested by skelterjohn
+
+// Event returns a new channel suitable for listening for events.
+func Event() chan struct{} {
+ return make(chan struct{}, eventbufsiz)
+}
+
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding:
type cSysData struct {
ctype int
@@ -56,7 +63,7 @@ func (c *cSysData) delete(int) error {
}
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
-// Thanks skelterjohn for this techinque: if we can't queue any more events, drop them; TODO this would be best if the channel is buffered
+// Thanks skelterjohn for this techinque: if we can't queue any more events, drop them
func (s *cSysData) signal() {
if s.event != nil {
go func() {