join_threads: simplify thread stoppage check
[rainbows.git] / lib / rainbows / join_threads.rb
blob7ab20044f5109cd7ae59e804fe4076057061ac4c
1 # -*- encoding: binary -*-
2 # :enddoc:
3 # This module only gets loaded on shutdown
4 module Rainbows::JoinThreads
6   # blocking acceptor threads must be forced to run
7   def self.acceptors(threads)
8     expire = Time.now + Rainbows.server.timeout
9     threads.delete_if do |thr|
10       Rainbows.tick
11       begin
12         # blocking accept() may not wake up properly
13         thr.raise(Errno::EINTR) if Time.now > expire && thr.stop?
15         thr.run
16         thr.join(0.01)
17       rescue
18         true
19       end
20     end until threads.empty?
21   end
22 end