Ruby multiple background threads

后端 未结 2 959
渐次进展
渐次进展 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
    

提交回复
热议问题