Never ending Ticker in the Golang only works 2 times

I am trying to create a channel with an infinite ticker, but it only works 2 times.

Could you help me understand what the problem is?

code:

package main 

import (
"fmt"
"time"
) 

var mark = [2]float64{8.9876, 762.098568}

func tick(out chan <- [2]float64){

    c := time.NewTicker(time.Millisecond *500)
    for range c.C{
        out <- mark
    }
}

func main() {

    fmt.Println("Start")

    md := make(chan [2]float64)
    go tick(md)

    for range <-md{
        fmt.Println(<-md)
    }
}

Output:

Start
[8.9876 762.098568]
[8.9876 762.098568]

Example: https://play.golang.org/p/P2FaUwbW-3

+6
source share
1 answer

It:

for range <-md{

- this is not the same as:

for range md{

( ), , , , , . , for, , ( , , ). :

for foo := range md{
    fmt.Println(foo)
}

, , " ", : https://play.golang.org/p/RSUJFvluU5

+8

All Articles