create a float channel in go

To create a float channel in Go, you need to first create a channel of type float64. You can do this using the make function, which creates a new channel of the specified type. Here is an example:

main.go
floatChan := make(chan float64)
32 chars
2 lines

Once you have created the float channel, you can use it to send and receive float values between goroutines. For example, you could have one goroutine send a float value on the channel, while another goroutine receives the value:

main.go
go func() {
    floatChan <- 3.14159
}()

value := <-floatChan
fmt.Println(value) // Output: 3.14159
101 chars
7 lines

In this example, we create a new goroutine using the go keyword, and inside the goroutine we send the float value 3.14159 on the floatChan channel using the <- operator. Then, in the main goroutine, we receive the value from the channel using the same operator.

Note that channels in Go are blocking by default, so if there is no value available to receive from the channel, the <- operator will block until a value is available. Similarly, if the channel is full and there is no goroutine available to receive the value, the <- operator used to send a value will block until there is room in the channel.

gistlibby LogSnag