D
D
DigiBeach2020-08-03 04:18:43
ruby
DigiBeach, 2020-08-03 04:18:43

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


I tried like this, but it's in turn

print 'get time'
window = gets.chomp()
window.times do 
  browser
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-08-03
@DigiBeach

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 question

Ask a Question

731 491 924 answers to any question