Skip to content

Commit

Permalink
Basic Goroutine calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya43 committed May 29, 2021
1 parent 789897e commit d766b1b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 01-goroutines/01-basic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"time"
)

func fun(s string) {
for i := 0; i < 3; i++ {
fmt.Println(s)
time.Sleep(1 * time.Millisecond)
}
}

func main() {
// Direct call
fun("direct call")

// TODO: write goroutine with different variants for function call.

// goroutine function call
go fun("Test 1")

// goroutine with anonymous function
go func() {
fun("Test 2")
}()

// goroutine with function value call
fn := fun
go fn("Test 3")

// wait for goroutines to end
time.Sleep(100 * time.Millisecond)

fmt.Println("done..")
}

0 comments on commit d766b1b

Please sign in to comment.