Giter VIP home page Giter VIP logo

each_in_thread's Introduction

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.

each_in_thread's People

Contributors

galaxy83 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.