diff options
Diffstat (limited to 'lib/rainbows/worker_yield.rb')
-rw-r--r-- | lib/rainbows/worker_yield.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/rainbows/worker_yield.rb b/lib/rainbows/worker_yield.rb new file mode 100644 index 0000000..ec2a289 --- /dev/null +++ b/lib/rainbows/worker_yield.rb @@ -0,0 +1,15 @@ +# :enddoc: +module Rainbows::WorkerYield + + # Sleep if we're busy (and let other threads run). Another less busy + # worker process may take it for us if we sleep. This is gross but + # other options still suck because they require expensive/complicated + # synchronization primitives for _every_ case, not just this unlikely + # one. Since this case is (or should be) uncommon, just busy wait + # when we have to. We don't use Thread.pass because it needlessly + # spins the CPU during I/O wait, CPU cycles that can be better used by + # other worker _processes_. + def worker_yield + sleep(0.01) + end +end |