Answer the question
In order to leave comments, you need to log in
How to run the def method several times not in a row, but simultaneously?
Good afternoon. I have a method which contains some actions. I need to call this method multiple times at the same time, how can I do that? It is so that the same task is performed several times at the same time, not in a row, but simultaneously.
For example method
def browser
driver = Selenium::WebDriver.for :chrome
driver.get("https://2ip.ru")
sleep 15
driver.close
end
print 'get time'
window = gets.chomp()
window.times do
browser
end
Answer the question
In order to leave comments, you need to log in
Example:
threads = []
10.times {
threads << Thread.new { puts 1 }
}
threads.each(&:join)
You just need not to overdo it with their number, so that there are enough resources.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question