Socket
Book a DemoInstallSign in
Socket

threadlimiter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

threadlimiter

0.2.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

ThreadLimiter forks threads like Thread.fork(), but limits the number of concurrently running threads.

ThreadLimiter isn't a thread pool. Each fork really starts a new thread.

Example: Get the titles of a large collections of URL's.

The traditional way, using Thread directly:

urls = [.....] # A lot of URL's. Maybe even thousends.

titles = urls.collect do |url| Thread.fork do # ...get the title of the url... end end.collect do |thread| thread.value end

With ThreadLimiter#fork():

require "threadlimiter"

urls = [.....] # A lot of URL's. Maybe even thousends. thread_limiter = ThreadLimiter.new(10) # Max. 10 concurrently running threads.

titles = urls.collect do |url| thread_limiter.fork do # ...get the title of the url... end end.collect do |thread| thread.value end

With Enumerable#threaded_collect():

require "threadlimiter"

urls = [.....] # A lot of URL's. Maybe even thousends.

titles = urls.threaded_collect(10) do |url| # Max. 10 concurrently running threads. # ...get the title of the url... end

FAQs

Package last updated on 17 Mar 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.