Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Example on Channels

package main

import (
    "fmt"
    "time"
    )
func printHello(c chan string) {
        c<- "\"Hello "
        time.Sleep(1* time.Second)
    }
    
func printWorld(c chan string) {
    time.Sleep(1* time.Second)
       c<- "World\" "
    }

func main() {
        start := time.Now()
    
   fmt.Print("This is my first concurrent ")
   c1:=make(chan string)
   c2:=make(chan string)
   go printHello(c1)
   go printWorld(c2)
   fmt.Println(<- c1,<- c2,"program")
   
   t := time.Now()
    elapsed := t.Sub(start)
    fmt.Println(elapsed)
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.