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

codegrinder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codegrinder

  • 0.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Will it grind ?

Yes, and in parallel !

codegrinder is a queue associated to one or several thread that share the same logic, and process the elements inserted into it.

How to install ?

gem install codegrinder

How to use ?

First, you have to require codegrinder:

require 'codegrinder'

Next, you have to build your codegrinder:

# That codegrinder print the square of any inserted value:
my_grinder = CodeGrinder.new { |i| print(String(i ** 2) + "\n") }

At last, you can start it:

# Starting the grinder with 4 threads. If no number is given, a single
# thread is used.
my_grinder.start(4)

From now on, any time you will insert a value in your grinder, it will be squared and printed to screen by one of your 4 threads.

Full example:

# Parallelized tiny pry-like implementation

STDOUT.sync = true
STDERR.sync = true

require 'codegrinder'

code_processor = CodeGrinder.new do |code|
  begin
    STDERR.write "  => #{eval(code).inspect}\n"
  rescue StandardError => e
    STDERR.write "  => #{e.class}: #{e.message}\n"
  end
end

code_processor.start(4)

QUIT = 'quit'

def self.next_command
  STDOUT.write("Enter command:\n")
  result = gets
  result.nil? ? QUIT : result.chomp
end

while (command = next_command) != QUIT
  code_processor << command
end

This small ruby shell can process up to 4 commands at the same time.

FAQs

Package last updated on 15 Aug 2015

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