Add Goroutines

This commit is contained in:
Sangeeth Sudheer 2024-04-27 15:14:51 +05:30
parent d3e9911fe5
commit 27dda5f2b6
Signed by: x
GPG Key ID: F6D06ECE734C57D1
3 changed files with 30 additions and 2 deletions

0
channels/channels.go Normal file
View File

26
goroutines/goroutines.go Normal file
View File

@ -0,0 +1,26 @@
package goroutines
import (
"fmt"
"time"
)
func print1To20(label string) {
for i := range 20 {
fmt.Printf("%s:%d\n", label, i+1)
}
}
func Goroutines() {
print1To20("Synchronous")
go print1To20("Goroutine 1")
go func(label string) {
print1To20(label)
}("Goroutine 2")
fmt.Println("Crudely waiting for 2 seconds")
time.Sleep(2 * time.Second)
fmt.Println("Done")
}

View File

@ -3,11 +3,13 @@ package main
// import "git.sangeeth.dev/gobyexample/runes" // import "git.sangeeth.dev/gobyexample/runes"
// import "git.sangeeth.dev/gobyexample/structs" // import "git.sangeeth.dev/gobyexample/structs"
// import "git.sangeeth.dev/gobyexample/generics" // import "git.sangeeth.dev/gobyexample/generics"
import "git.sangeeth.dev/gobyexample/errors" // import "git.sangeeth.dev/gobyexample/errors"
import "git.sangeeth.dev/gobyexample/goroutines"
func main() { func main() {
// runes.Runes() // runes.Runes()
// structs.Structs() // structs.Structs()
// generics.Generics() // generics.Generics()
errors.Errors() // errors.Errors()
goroutines.Goroutines()
} }