Ruby multiple background threads

后端 未结 2 953
渐次进展
渐次进展 2021-01-14 20:57

I need to run multiple background threads in a thread pool with timeout. The scheme is something like:

    #!/usr/bin/env ruby

require \'thread\'

def foo(&         


        
相关标签:
2条回答
  • 2021-01-14 21:05

    The program ends when the main thread ends. You have to wait on the thread created by bar using join:

    foo {
      sleep 1
      puts 'test'
    }.join
    
    0 讨论(0)
  • 2021-01-14 21:21

    Try the work_queue gem http://rubygems.org/gems/work_queue/

    0 讨论(0)
提交回复
热议问题