Skip to content

Instantly share code, notes, and snippets.

@igrep
Created December 29, 2010 05:46
Show Gist options
  • Save igrep/758224 to your computer and use it in GitHub Desktop.
Save igrep/758224 to your computer and use it in GitHub Desktop.
Queue#to_enum( wait_thread )
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
=begin
Queue#to_enum
=end
require 'thread'
class Queue
def to_enum wait_thread
class << self
def each &block
block[ self.deq ] while wait_thread.alive?
block[ self.deq ] until self.empty?
end
end
self.extend Enumerable
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment