Last active
April 27, 2020 03:27
-
-
Save codenoid/6ea84492d24b3c76837f2e586366adcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"runtime" | |
"time" | |
) | |
func main() { | |
http.HandleFunc("/", HelloServer) | |
go http.ListenAndServe(":8080", nil) | |
for { | |
fmt.Printf("Total Goroutine yang lagi di pake : %v\n", runtime.NumGoroutine()) | |
time.Sleep(200 * time.Millisecond) | |
} | |
} | |
// route dipanggil 1 | |
// route diproses 1 | |
func HelloServer(w http.ResponseWriter, r *http.Request) { | |
fmt.Println("route dipanggil") | |
go func() { | |
// proses yang jalan selama 5 detik | |
fmt.Println("goroutine didalem route dibuat") | |
time.Sleep(7 * time.Second) | |
}() | |
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) | |
// sync process yang jalan selama 3 detik | |
time.Sleep(3 * time.Second) | |
fmt.Println("route done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment