-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
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
endWhich 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)
endIs that useful? Maybe. We'll see. But we're going to build it anyway. 😄
Metadata
Metadata
Assignees
Labels
No labels