Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Use multithreading #24

Open
timbru31 opened this issue May 30, 2017 · 1 comment
Open

Use multithreading #24

timbru31 opened this issue May 30, 2017 · 1 comment

Comments

@timbru31
Copy link
Owner

Examine how to check multiple mp3 files at the same time.

@timbru31 timbru31 changed the title Using multithreading Use multithreading May 30, 2017
@timbru31
Copy link
Owner Author

Example could be something like this:

POOL_SIZE = 10

jobs = Queue.new

10_0000.times{|i| jobs.push i}

workers = (POOL_SIZE).times.map do
  Thread.new do
    begin      
      while x = jobs.pop(true)
        Mailer.deliver do 
          from    "eki_#{x}@eqbalq.com"
          to      "jill_#{x}@example.com"
          subject "Threading and Forking (#{x})"
          body    "Some content"
        end        
      end
    rescue ThreadError
    end
  end
end

workers.map(&:join)

(https://www.toptal.com/ruby/ruby-concurrency-and-parallelism-a-practical-primer)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant