vkorbes / aprendago

Curso completo em português da linguagem Go, de zero a ninja! 🇧🇷
http://aprendago.com
991 stars 180 forks source link

Exercício: Capítulo 22, Exercício 1 (Nível: 10) #66

Open vkorbes opened 3 years ago

vkorbes commented 3 years ago

Exercício: Capítulo 22, Exercício 1 (Nível: 10)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

haystem commented 3 years ago

solução 1: https://play.golang.org/p/2D84B7z781O solução 2: https://play.golang.org/p/4PPAfh7W5Tx

an4kein commented 3 years ago

https://play.golang.org/p/cmBIx9_9gfH

package main

import (
    "fmt"
)

func main() {
    c := make(chan int)
    go func() {
        c <- 42
    }()

    fmt.Println(<-c)
}

Output

42

Program exited.

https://play.golang.org/p/xO9iOSsbmWH

package main

import (
    "fmt"
)

func main() {
    c := make(chan int, 1)

    c <- 42

    fmt.Println(<-c)
}

Output

42

Program exited.
Harsgaard commented 1 year ago

buffer: https://go.dev/play/p/xO9iOSsbmWH go func: https://go.dev/play/p/0KEjX2prAIG

LelecoNN commented 8 months ago

Playground

package main

import (
    "fmt"
)

func main() {
    c := make(chan int)
    go func() {
        c <- 42
    }()
    fmt.Println(<-c)

}