Skip to content

Instantly share code, notes, and snippets.

@CheatEx
Created April 19, 2024 16:12
Show Gist options
  • Save CheatEx/1fb164679e25b64c7b41645c4058ccec to your computer and use it in GitHub Desktop.
Save CheatEx/1fb164679e25b64c7b41645c4058ccec to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"os"
"sync"
"time"
)
func main() {
start := &sync.WaitGroup{}
end := &sync.WaitGroup{}
log.Println("pid: %d", os.Getpid())
http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Minute)
_, err := fmt.Fprintf(w, "Hello!")
if err != nil {
log.Println("print error: ", err)
}
})
go func() {
log.Fatal(http.ListenAndServe(":8080", nil))
}()
time.Sleep(5 * time.Second)
for i := 0; i < 9999; i++ {
start.Add(1)
end.Add(1)
go func() {
start.Done()
_, err := http.Get("http://localhost:8080/test")
if err != nil {
log.Println("get error: ", err)
}
end.Done()
}()
}
start.Wait()
log.Println("Ready: ", time.Now())
end.Wait()
log.Println("Finished: ", time.Now())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment