diff options
author | xegineering <me@xegineering.eu> | 2024-11-29 10:16:57 +0100 |
---|---|---|
committer | xegineering <me@xegineering.eu> | 2024-11-29 10:16:57 +0100 |
commit | f5f0d12b697e71e67a403791c1b93ffdf61e272a (patch) | |
tree | 54da8ee9925b47c1efa02e1e9f0118bbdec37026 | |
parent | 97af30e8fee2274a437a13d8c2c19e4bfe29ddee (diff) | |
download | soundbox-go-f5f0d12b697e71e67a403791c1b93ffdf61e272a.tar soundbox-go-f5f0d12b697e71e67a403791c1b93ffdf61e272a.tar.zst soundbox-go-f5f0d12b697e71e67a403791c1b93ffdf61e272a.zip |
Refactor streamContext()
This avoids an unnecessary additional for loop.
-rw-r--r-- | soundbox/streaming.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/soundbox/streaming.go b/soundbox/streaming.go index 357fa30..3eb237d 100644 --- a/soundbox/streaming.go +++ b/soundbox/streaming.go @@ -13,24 +13,23 @@ const writeTimeout = 1 * time.Second func streamContext(ctx context.Context, r io.Reader, targets []net.HardwareAddr) error { conns := make([]net.Conn, 0) + writers := make([]io.Writer, 0) + for _, target := range targets { conn, err := dialContext(ctx, target) if err != nil { return err } conns = append(conns, conn) + writers = append(writers, conn) } + defer func() { for _, conn := range conns { conn.Close() } }() - writers := make([]io.Writer, 0) - for _, conn := range conns { - writers = append(writers, conn) - } - mw := io.MultiWriter(writers...) buf := make([]byte, bufferSize) |