Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A proof-of-concept limited-thread-count worker example thingy.

View thread-test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
require 'threadpuddle'
puddle = ThreadPuddle.new 10
@array = (1..100).to_a
 
while @array.size > 0
# this shift is not synced because '@array'
# is only accessed from the one thread
item = @array.shift
#print "popped item #{item.inspect} at time #{Time.now.strftime '%H:%M:%S.%6N'} Puddle size is #{puddle.size}\n"
puddle.spawn(item) do |i|
# simulate some long-running, not entirely
# uniformly timed operation
sleep(rand/2+0.01)
p i
end
end
puddle.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.