concur

2.1.1last stable release 12 years ago
Complexity Score
Low
Open Issues
1
Dependent Projects
4
Weekly Downloadsglobal
827

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

Concur - A concurrency library for Ruby inspired by java.util.concurrency and Go (golang).

Getting Started

Install gem:

gem install concur

General Usage

# Choose which executor you want, there are several to choose from
executor = Concur::Executor.new_thread_pool_executor(10)
start_time = Time.now

jobs = []
times.times do |i|
  future = executor.execute do
    puts "hello #{i}"
    "result #{i}" # this is what will be returned from the Future
  end
  jobs << future
end
jobs.each do |j|
  puts "uber fast result=#{j.get}"
end
pooled_duration = Time.now - start_time
puts "pooled_duration=" + pooled_duration.to_s
executor.shutdown

Futures

A Future is what is returned from the execute method. Call future.get to get the results of the block or the Callable object. If it’s not finished, get will block until it is. get will also raise an Exception if an Exception occurred during running.

EventMachine / Non-blocking I/O

DEPRECATED!!

Perhaps more important/interesting these days is EventMachine/non-blocking io. When your program is io bound you can get similar performance (if not better) on a single thread as you can with multi-threads.

# Create an EventMachineExecutor
executor = Concur::Executor.new_eventmachine_executor()

# Now fire off a bunch of http requests
futures = []
TestConcur.urls.each do |url|
  params_to_send = {}
  params_to_send[:base_url] = url
  params_to_send[:path] = "/"
  params_to_send[:http_method] = :get
  futures << executor.http_request(params_to_send)
end
futures.each do |f|
  puts 'got=' + f.get.inspect
  assert f.get.status >= 200 && f.get.status < 400
end

See https://github.com/appoxy/concur/blob/master/test/test_concur.rb for more examples.

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
Yes
Github Stars
9
Dependenciestotal
1
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute concur in your own private RubyGems registry

gem install concur
Processing...
Done

15 Releases

RubyGems on Cloudsmith

Getting started with RubyGems on Cloudsmith is fast and easy.