From 0e1294eb8ee83567cc76c5f3c49fb494636e150d Mon Sep 17 00:00:00 2001 From: "a.pivkin" Date: Wed, 31 Dec 2025 13:08:10 +0300 Subject: [PATCH] sf --- .../goroutines/clock_server/go.mod | 3 ++ .../goroutines/clock_server/main.go | 46 +++++++++++++++++++ book_with_bridge/goroutines/spinner/go.mod | 3 ++ book_with_bridge/goroutines/spinner/main.go | 15 ++++++ 4 files changed, 67 insertions(+) create mode 100644 book_with_bridge/goroutines/clock_server/go.mod create mode 100644 book_with_bridge/goroutines/clock_server/main.go create mode 100644 book_with_bridge/goroutines/spinner/go.mod create mode 100644 book_with_bridge/goroutines/spinner/main.go diff --git a/book_with_bridge/goroutines/clock_server/go.mod b/book_with_bridge/goroutines/clock_server/go.mod new file mode 100644 index 0000000..371eb8f --- /dev/null +++ b/book_with_bridge/goroutines/clock_server/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.25.5 diff --git a/book_with_bridge/goroutines/clock_server/main.go b/book_with_bridge/goroutines/clock_server/main.go new file mode 100644 index 0000000..c7e3df9 --- /dev/null +++ b/book_with_bridge/goroutines/clock_server/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "io" + "log" + "net" + "time" +) + +type newWriter struct { + conn io.Writer +} + +func (nw newWriter) Write(p []byte) (n int, err error) { + prefix := []byte("curr time is ") + prefix = append(prefix, p...) + n, err = nw.conn.Write(prefix) + return +} + +func handleConn(conn net.Conn) { + defer conn.Close() + + for { + _, err := io.WriteString(newWriter{conn}, time.Now().Format("15:04:05\n")) + if err != nil { + return + } + time.Sleep(1 * time.Second) + } +} + +func main() { + listener, err := net.Listen("tcp", ":9090") + if err != nil { + log.Fatalf("Shit happened %s",err) + } + for { + conn, err := listener.Accept() + if err != nil { + log.Printf("Error is %s",err) + continue + } + go handleConn(conn) + } +} diff --git a/book_with_bridge/goroutines/spinner/go.mod b/book_with_bridge/goroutines/spinner/go.mod new file mode 100644 index 0000000..371eb8f --- /dev/null +++ b/book_with_bridge/goroutines/spinner/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.25.5 diff --git a/book_with_bridge/goroutines/spinner/main.go b/book_with_bridge/goroutines/spinner/main.go new file mode 100644 index 0000000..28a823e --- /dev/null +++ b/book_with_bridge/goroutines/spinner/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + for { + for _,r := range `-\|/` { + fmt.Printf("\r processing in progress %c",r) + time.Sleep(50*time.Millisecond) + } + } +} \ No newline at end of file