Answer the question
In order to leave comments, you need to log in
Another incomprehensible situation with Go?
Hello everyone, straight to the point. The code:
for _ = range time.Tick(3 * time.Second) {
fmt.Println("Making query")
rows, err := db.Query("SELECT id, addr, method FROM tasks")
defer rows.Close()
if err != nil {
fmt.Printf("Database error: %s\n", err.Error())
os.Exit(1)
} else {
fmt.Println("Filling queue")
queue := make(chan *Task)
for rows.Next() {
fmt.Println("Get next row")
var id int32
var addr string
var method string
if err := rows.Scan(&id, &addr, &method); err != nil {
fmt.Printf("Row error: %s\n", err.Error())
} else {
fmt.Printf("Add task for: %s\n", addr)
queue <- &Task{id, addr, method}
fmt.Println("Task added")
}
}
fmt.Println("Queue filled")
close(queue)
process(queue)
}
}
queue <- &Task{id, addr, method}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question