Skip to content

Instantly share code, notes, and snippets.

@wedesoft
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wedesoft/a6af5f02e412c9ccf405 to your computer and use it in GitHub Desktop.
Save wedesoft/a6af5f02e412c9ccf405 to your computer and use it in GitHub Desktop.
Background task in Ruby
#!/usr/bin/env ruby
def task n
result = 0
for i in 1 ... n
result += i
sleep 0.01
end
result
end
t = Thread.new 100, &method(:task)
while t.alive?
sleep 0.1
STDOUT.print '*'
STDOUT.flush
end
STDOUT.print "\n"
p t.value
# **********
# 4950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment