Bladeren bron

Runtime chan send. Fixed leak in input demo.

We were leaking a go routine.
Bugz 1 jaar geleden
bovenliggende
commit
6b631d28ba
2 gewijzigde bestanden met toevoegingen van 15 en 5 verwijderingen
  1. 3 1
      testdoor/runtime-info.go
  2. 12 4
      testdoor/testdoor.go

+ 3 - 1
testdoor/runtime-info.go

@@ -28,9 +28,11 @@ func GoRoutinesStatus() string {
 		"sleep":        "S",
 		"select":       "s", // missing
 		"chan receive": "<", // missing
+		"chan send":    ">",
 	}
+	// 2K works, we don't have to grow any more.
 	if buffer == nil {
-		buffer = make([]byte, 1024) // 2048)
+		buffer = make([]byte, 2048)
 	}
 	read := runtime.Stack(buffer, true)
 

+ 12 - 4
testdoor/testdoor.go

@@ -474,12 +474,19 @@ func font_demo(d *door.Door) {
 
 func input_demo(d *door.Door) {
 	var ticker *time.Ticker = time.NewTicker(time.Second)
+	var StopIt = make(chan bool)
 
 	go func() {
-		for t := range ticker.C {
-			const tf = "January 2, 2006 03:04:05 PM MST"
-			output := door.SavePos + door.Goto(5, 2) + door.ColorText("BRI WHI ON CYAN") + t.Format(tf) + door.RestorePos
-			d.Write(output)
+		for {
+			select {
+			case <-StopIt:
+				return
+
+			case t := <-ticker.C:
+				const tf = "January 2, 2006 03:04:05 PM MST"
+				output := door.SavePos + door.Goto(5, 2) + door.ColorText("BRI WHI ON CYAN") + t.Format(tf) + door.RestorePos
+				d.Write(output)
+			}
 		}
 	}()
 
@@ -499,6 +506,7 @@ func input_demo(d *door.Door) {
 	var color string = d.Input(15)
 	d.Write(door.Reset + door.CRNL)
 	ticker.Stop()
+	StopIt <- true
 	d.Write(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
 }