ultrago/reactive/net.go

24 lines
488 B
Go
Raw Normal View History

2024-08-13 16:20:52 +00:00
package reactive
import (
"net"
"net/netip"
)
func Listen(network string, address string) (Observable[net.Conn], error) {
lis, err := net.Listen(network, address)
if err != nil {
return nil, err
}
return BlockingLoop(lis.Accept), nil
}
func ListenTCP(network string, address netip.AddrPort) (Observable[*net.TCPConn], error) {
lis, err := net.ListenTCP("tcp", net.TCPAddrFromAddrPort(address))
if err != nil {
return nil, err
}
return BlockingLoop(lis.AcceptTCP), nil
}