From 9e917844ff3ed3248bd37d31c8da819887ee898f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20G=C3=B6r?= Date: Sun, 21 Jan 2024 19:18:44 +0300 Subject: [PATCH] go routine example 1 --- goroutines/demo1.go | 7 ++++++- main.go | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/goroutines/demo1.go b/goroutines/demo1.go index 66248b9..afb12d2 100644 --- a/goroutines/demo1.go +++ b/goroutines/demo1.go @@ -1,15 +1,20 @@ package goroutines -import "fmt" +import ( + "fmt" + "time" +) func EvenNumber() { for i := 0; i <= 10; i+=2 { fmt.Println("Even Number : ", i) + time.Sleep(1 * time.Second) } } func OddNumber() { for i := 1; i <= 10; i+=2 { fmt.Println("Odd Number : ", i) + time.Sleep(1 * time.Second) } } \ No newline at end of file diff --git a/main.go b/main.go index f063165..665a40a 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "golesson/slices" "golesson/structs" "golesson/variables" + "time" ) func main() { @@ -57,6 +58,8 @@ func main() { structs.Demo1() structs.Demo2() - goroutines.EvenNumber() - goroutines.OddNumber() + go goroutines.EvenNumber() + go goroutines.OddNumber() + time.Sleep(5 * time.Second) + fmt.Println("Main ended") }