summaryrefslogtreecommitdiff
path: root/debugGochan.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-03-03 14:41:38 -0600
committerJeff Carr <[email protected]>2023-03-03 14:41:38 -0600
commit49202eeafdad8e5780fefdad3d2f87fd4354725e (patch)
tree5d749b5d4835c7a0395bd1f87b5d2d1d91b14a08 /debugGochan.go
parent80317ec89c94beadcbf3775f84c6010b5ceef302 (diff)
release as v0.6.5v0.6.5
good standard release really clean interaction to plugin really clean debug flags implementation common doAppend() idea, but it probably won't work re-implement combobox. this code base almost doesn't suck slider & spinner set values now tab set margin works convert dropdown to Send() lots of other changes to try to implement single line Entry() I guess use golang file names even though internalally the go developers use underscore chars in the actual go sources. Maybe there is a reason for that? go channel debug window does something make a debug window for channels. add sample icons Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'debugGochan.go')
-rw-r--r--debugGochan.go107
1 files changed, 107 insertions, 0 deletions
diff --git a/debugGochan.go b/debugGochan.go
new file mode 100644
index 0000000..3183bdb
--- /dev/null
+++ b/debugGochan.go
@@ -0,0 +1,107 @@
+// https://www.digitalocean.com/community/tutorials/how-to-run-multiple-functions-concurrently-in-go
+// who came up with the idea of making community tutorials. that was a good idea!
+
+package gui
+
+import (
+ "fmt"
+ "sync"
+)
+
+var debugWG *sync.WaitGroup
+var debugNumberChan chan int
+
+func (n *Node) debugGoChannels(makeWindow bool) {
+ var w, g *Node
+
+ // Either:
+ // make a new window
+ // make a new tab in the existing window
+ if (makeWindow) {
+ Config.Title = "Debug GO Channels"
+ Config.Width = 300
+ Config.Height = 400
+ w = NewWindow()
+ w.Custom = w.StandardClose
+ } else {
+ w = n.NewTab("Chan")
+ }
+ w.Dump()
+
+ g = w.NewGroup("Channel stuff")
+
+ // var debugWG sync.WaitGroup
+ g.NewButton("init()", func () {
+ if (debugNumberChan == nil) {
+ log("making debugNumberChan channel")
+ debugNumberChan = make(chan int)
+ } else {
+ log("debugNumberChan already made")
+ }
+ debugWG = new(sync.WaitGroup)
+ })
+ g.NewButton("go printInt(x) (read x values off the channel)", func () {
+ debugWG.Add(1)
+ go printInt(2, "routine1")
+ debugWG.Add(1)
+ go printInt(2, "routine2")
+ })
+ g.NewButton("sendNumber(2) (chan <- 2, 4)", func () {
+ debugWG.Add(1)
+ debugWG.Add(1)
+ go sendNumber(2)
+ go sendNumber(4)
+ })
+ g.NewButton("sendNumber(1) (chan <- 7)", func () {
+ debugWG.Add(1)
+ go sendNumber(7)
+ })
+ g.NewButton("send 4 numbers (chan <- int)", func () {
+ log("generateNumbers(4)")
+ go generateNumbers(4)
+ })
+ g.NewButton("debugWG.Done()", func () {
+ log("ran debugWG.Done()")
+ debugWG.Done()
+ })
+ g.NewButton("close chan", func () {
+ close(debugNumberChan)
+ })
+ g.NewButton("print", func () {
+ log("waitgroup counter is ?")
+ })
+}
+func sendNumber(i int) {
+ log("START debugNumberChan <-", i, " (sending", i, "to channel)")
+ debugNumberChan <- i
+ debugWG.Wait()
+ log("END debugNumberChan sendNumber() done", i)
+}
+
+func generateNumbers(total int) {
+ fmt.Printf("START generateNumbers()\n")
+ for idx := 1; idx <= total; idx++ {
+ log("ran debugNumberChan <= idx where idx =", idx)
+ fmt.Printf("S generateNumbers() sending %d to channel\n", idx)
+ debugNumberChan <- idx
+ // res, err := (<-r)()
+ fmt.Printf("E generateNumbers() sending %d to channel\n", idx)
+ }
+ debugWG.Wait()
+ fmt.Printf("END generateNumbers()\n")
+}
+
+// i equals the number of times to read values from the channel
+func printInt(i int, name string) {
+ tmp := 1
+ log("START printInt", name, "read debugNumberChan()")
+ for num := range debugNumberChan {
+ log("printInt()",name, "read", num, "from channel")
+ debugWG.Done()
+ if (tmp == i) {
+ return
+ }
+ tmp += 1
+ }
+ fmt.Printf("END printInt()", name, "read debugNumberChan\n")
+}