commander~snluu

A small library to manage concurrently spawned jobs
HEAD Latest release released
snluu/commander
5
Steven Luu

commander

Build Status

Commander is a simple shard that lets you dispatch many concurrent calls at once, then collect the result afterwards.

Commander also allows the caller to choose the maximum concurrency for the given job.

API doc can be found at https://www.luu.io/projects/commander/api/

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  commander:
    github: snluu/commander
  1. Run shards install

Usage

See the spec for more details/examples.

require "commander"

cmd = Commander(Int32).new
result = nil

elapsed = Time.measure do
  1000.times do |x|
    cmd.dispatch do
      sleep 1.seconds
      x
    end
  end

  result = cmd.collect
end

result = result.not_nil!
result.size.should eq(1000)
1000.times do |x|
  result.should contain(x)
end

# 5 seconds is a very generous buffer.
# The point is it should not take 1000 seconds
elapsed.should be < 5.seconds

commander:
  github: snluu/commander
  
License MIT
Crystal 0.32.1

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently