Last active
August 29, 2015 14:23
-
-
Save wedesoft/a6af5f02e412c9ccf405 to your computer and use it in GitHub Desktop.
Background task in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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