Skip to content

TCPServer #2

Description

@hamiltop

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. 😄

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions