Skip to content

Instantly share code, notes, and snippets.

@bensonk
Created July 11, 2010 03:28
Show Gist options
  • Select an option

  • Save bensonk/471254 to your computer and use it in GitHub Desktop.

Select an option

Save bensonk/471254 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class DeferredThread < Object
def initialize &code
@proc = code
end
def invoke
Thread.new { @proc.call }
end
end
deferred_threads = (1..100).collect do |i|
DeferredThread.new do
puts "first: #{i}"
Thread.pass
puts "second: #{i}"
end
end
deferred_threads.each(&:invoke)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment