Created
January 23, 2022 16:27
-
-
Save manjeettahkur/644c4c37259a799ef850a6538a0dff5f 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 ( | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
log.Println("Starting server on localhost:9090") | |
http.Handler_sync("/sync", Handler) | |
http.Handler_async("/async", Handler) | |
http.ListenAndServe(":9090", nil) | |
} | |
func Handler_async(_ http.ResponseWriter, _ *http.Request) { | |
log.Println("Entered Handler") | |
defer func() { | |
go func() { | |
time.Sleep(5 * time.Second) | |
log.Println("Exiting goroutine") | |
}() | |
log.Println("Exiting defer") | |
}() | |
} | |
func Handler_sync(_ http.ResponseWriter, _ *http.Request) { | |
log.Println("Entered Handler") | |
defer func() { | |
time.Sleep(5 * time.Second) | |
log.Println("Exiting defer") | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment