streamz icon indicating copy to clipboard operation
streamz copied to clipboard

TCPServer

Open hamiltop opened this issue 11 years ago • 1 comments

TCPServer is going to be implemented as a stream of streams. It seems a little excessive, but that's sort of what Streamz is about. We won't know how useful something is until we build it and try using it. The target api is:

server_stream = TCPServer.start_link([port: 1234])
server_stream |> Enum.each fn (socket_stream) ->
  spawn_link fn ->
    socket_stream |> Enum.into(socket_stream) # This is an echo server
  end
end

Which would more likely look like:

server_stream = TCPServer.start_link([port: 1234])
server_stream |> Enum.each &EchoServerSupervisor.start_child(&1)

That's a fairly normal pattern. Some interesting things can happen here. What if we wanted to trace 1 out of 10 connections:

a_b_stream = Stream.cycle(List.duplicate(:no_trace, 9) ++ [:trace]])
server_stream = TCPServer.start_link([port: 1234])
server_stream |> Stream.zip(a_b_stream) |> Enum.each fn
  (socket, :no_trace) ->  &EchoServerSupervisor.start_child(&1)
  (socket, :trace) ->  &EchoServerWithTraceSupervisor.start_child(&1)
end

Is that useful? Maybe. We'll see. But we're going to build it anyway. :smile:

hamiltop avatar Jul 20 '14 07:07 hamiltop

Interesting idea from a design standpoint

server |> Stream.map(break_into_requests) |> Streamz.merge

That would work great for a graphite server, where you are just collecting data from multiple sources.

hamiltop avatar Aug 17 '14 01:08 hamiltop