-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSYNC VS ASYNC1.go
More file actions
72 lines (45 loc) · 1.21 KB
/
Copy pathSYNC VS ASYNC1.go
File metadata and controls
72 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main // main goroutine
import (
"fmt"
)
/* '' SYNC CODE Function + OOPS { struct, method , interface}
CODE EXECUTION DEPENDS ON THE DATA INSIDE THE MEMORY
''*/
func synccopy(fees int) {
fees = 85000
if fees <= 80000 {
panic("not allowed for course")
}
}
func sync() {
var course string = "golang"
var fees int
if course != "golang" {
fees = 75000
}
synccopy(fees)
fmt.Println("sync function ")
} // release memory stack
/* Devloper allocates memory for sync concepts */
/*'' A SYNC CODE Function => goroutine
CODE EXECUTION DEPENDS ON THE DATA INSIDE THE CHANNEL MEMORY { HEAP MEMORY}
the channel memory is not residing in the same function outside
''*/
func async(cha chan string) {
fmt.Println("async function started ")
var course string = <-cha
var fees int
if course != "golang" {
fees = 75000
}
synccopy(fees)
fmt.Println("async function end ")
}
func main() { // main_main
var cha chan string = make(chan string)
go async(cha) // stack is allocated by os
sync() // stack + heap + register
fmt.Println("before writing in to channel ")
cha <- "golang"
fmt.Println(" end of main")
}