Skip to content

Echo Server does not work #1011

Answered by bensheldon
marek22k asked this question in Q&A
Sep 30, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

If you need more than 1 thread, I don't think Concurrent::Async is the right tool, because it will only ever allocate 1 task thread for your object.

I think what you want is to instantiate a thread pool (or use the global io pool, though it is unbounded) and then create Concurrent::Future / Promises that use that pool.

Something that looks like this (sorry, this is off the top of my head, so it might have some typos):

def initialize
  @thread_pool = Concurrent::FixedThreadPool.new(3)
end

def run
  Concurrent::Future.new(executor: @thread_pool) do
    loop do
      break unless @thread_pool.running?  
      socket = @server.accept
      Concurrent::Future.new(executor: @thread_pool, args: [

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@marek22k
Comment options

@bensheldon
Comment options

Answer selected by marek22k
@marek22k
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants