Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

each_in_thread

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

each_in_thread

  • 0.1.12
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EachInThread

Gem Version

The each_in_thread gem extends Ruby's Enumerable module to provide an easy way to iterate over collections with concurrency. This means you can perform actions on each item in an array (or any other enumerable) in separate threads.

Installation

Add this line to your application's Gemfile:

gem 'each_in_thread'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install each_in_thread

Usage

require 'each_in_thread'
require 'net/http'

# Suppose we have an array of URLs we want to fetch.
urls = %w[http://example.com http://example.org http://example.net]

# We can fetch each URL in a separate thread like this:
urls.each_in_thread(concurrency: 5) do |url, i|
  response = Net::HTTP.get(URI(url))
  puts "(#{i}) Fetched #{url}: #{response.size} bytes"
end

The each_in_thread method takes an options hash, where you can specify the following:

  • concurrency: The number of threads to use. Defaults to 10.
  • log_each: The number of iterations between each progress output. Defaults to 1.
  • verbose: Whether to output progress. Defaults to false.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Galaxy83/each_in_thread. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 06 Nov 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc