On branch timer

Changes to be committed:
	modified:   main.go
		Adding use of time package directly
	modified:   timer/timer.go
		Simplifying this away.
pseudocode
Mike Holloway 4 years ago
parent bb77957ed4
commit 8e2f4e3db8
  1. 21
      main.go
  2. 28
      timer/timer.go

@ -1,7 +1,8 @@
package main package main
import ( import (
"./timer" //"./timer"
"time"
"fmt" "fmt"
"strings" "strings"
"regexp" "regexp"
@ -10,6 +11,8 @@ import (
) )
var tcp_data string = read_tcp_file("/proc/net/tcp")
func main() { func main() {
// How to split on space-delimited fields, then colon-delimited fields? // How to split on space-delimited fields, then colon-delimited fields?
// How to turn this byte into a string? // How to turn this byte into a string?
@ -18,8 +21,20 @@ func main() {
// and then converted byte by byte (2 char at a time) // and then converted byte by byte (2 char at a time)
//fmt.Println(convert_address(reverse_string(reverse_bytes("0100007F")))) //fmt.Println(convert_address(reverse_string(reverse_bytes("0100007F"))))
timer.New() // tensec := timer.New(10, "Second")
tcp_rows(read_tcp_file("/proc/net/tcp")) // onemin := timer.New(1, "Minute")
// tensec.Reset(
tensec := time.NewTimer(10 * time.Second)
onemin := time.NewTimer(1 * time.Minute)
// if !tensec.Stop() {
// fmt.Println("Done waiting 10 seconds!")
// }
fmt.Println("Waiting 10 seconds...")
<-tensec.C
tcp_rows(tcp_data)
fmt.Println("Waiting 1 minute...")
<-onemin.C
tcp_rows(tcp_data)
} }
func check(e error) { func check(e error) {

@ -6,16 +6,30 @@ import (
//"reflect" //"reflect"
) )
func New() { func New(duration_int int, unit string) *time.Timer {
timer_10s := time.NewTimer(10 * time.Second) start := time.NewTimer(0)
duration := time.Duration(duration_int)
// fmt.Println(reflect.TypeOf(duration))
// timer_10s := time.NewTimer(10 * time.Second)
// timer_1m := time.NewTimer(1 * time.Minute) // timer_1m := time.NewTimer(1 * time.Minute)
fmt.Println("Waiting 10 seconds...") fmt.Println("Duration: ", duration_int, "Unit: ", unit, ".")
<-timer_10s.C if unit == "Second" {
start = time.NewTimer(duration * time.Second)
} else if unit == "Minute" {
start = time.NewTimer(duration * time.Minute)
} else {
fmt.Println("Unit not recognized.")
}
fmt.Println("Waiting ", duration_int, " ", unit, ".")
if start.Stop() {
<-start.C
fmt.Println("Done waiting ", duration_int, " ", unit, "!")
}
return start
// for elapsed < ten_seconds { // for elapsed < ten_seconds {
//} //}
// for // for
} }
func Reset

Loading…
Cancel
Save