new version

This commit is contained in:
a.pivkin
2025-12-15 20:20:11 +03:00
parent 75066c8a08
commit 4e051565e2
34 changed files with 641 additions and 331 deletions
+10 -41
View File
@@ -1,51 +1,20 @@
package main
import (
"fmt"
"os"
"strconv"
"sync"
"log"
"net/http"
)
func go1(ch chan<- string, wg1 *sync.WaitGroup) {
defer wg1.Done()
for i := 1; i < 11; i++ {
ch <- "go1_" + strconv.Itoa(i)
}
}
func go2(ch chan<- string, wg1 *sync.WaitGroup) {
defer wg1.Done()
for i := 1; i < 11; i++ {
ch <- "go2_" + strconv.Itoa(i)
}
}
func Reader(ch <-chan string, wg *sync.WaitGroup) {
defer wg.Done()
for {
if v, ok := <-ch; !ok {
fmt.Println("Channel closed")
os.Exit(1)
} else {
fmt.Println(v)
}
}
func lol(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("azazaza"))
}
func main() {
var wg1 sync.WaitGroup
var wg sync.WaitGroup
wg.Add(1)
wg1.Add(2)
ch := make(chan string)
go go1(ch, &wg1)
go go2(ch, &wg1)
go Reader(ch, &wg)
http.HandleFunc("/",lol)
go func() {
wg1.Wait()
close(ch)
}()
wg.Wait()
s := http.Server{
Addr: ":9000",
}
log.Fatal(s.ListenAndServe())
}