concur 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -0
- data/lib/concur.rb +3 -0
- data/lib/executor.rb +10 -0
- data/lib/future.rb +28 -0
- data/lib/runnable.rb +10 -0
- data/test/executor_spec.rb +37 -0
- data/test/job.rb +16 -0
- metadata +56 -0
data/README.markdown
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Concur - A concurrency library for Ruby like java.util.concurrency
|
data/lib/concur.rb
ADDED
data/lib/executor.rb
ADDED
data/lib/future.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
=begin
|
2
|
+
An Future is a class that captures the results of a threaded object so you can retreive these results later.
|
3
|
+
|
4
|
+
Example usage:
|
5
|
+
|
6
|
+
searcher = Searcher.new
|
7
|
+
# todo: not sure if this will be usage in the end.... but
|
8
|
+
future = Future.new(searcher)
|
9
|
+
do_some_other_stuff_in_the_meantime()
|
10
|
+
search_results = future.get
|
11
|
+
|
12
|
+
`get` retrieves the results.
|
13
|
+
=end
|
14
|
+
module Concur
|
15
|
+
class Future
|
16
|
+
def initialize(runnable)
|
17
|
+
@thread = Thread.new do
|
18
|
+
@result = runnable.run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns results. Will wait for thread to complete execution if not already complete.
|
23
|
+
def get
|
24
|
+
@thread.join
|
25
|
+
@result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/runnable.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
require_relative '../lib/executor'
|
4
|
+
require_relative 'job'
|
5
|
+
|
6
|
+
describe Concur::Executor do
|
7
|
+
describe "#score" do
|
8
|
+
it "runs faster in parallel" do
|
9
|
+
start_time = Time.now
|
10
|
+
20.times do |i|
|
11
|
+
job = Job.new(i)
|
12
|
+
job.run
|
13
|
+
end
|
14
|
+
non_concurrent_duration = Time.now - start_time
|
15
|
+
puts "duration=" + non_concurrent_duration.to_s
|
16
|
+
|
17
|
+
puts
|
18
|
+
|
19
|
+
puts "Now for concurrent"
|
20
|
+
executor = Concur::Executor.new
|
21
|
+
start_time = Time.now
|
22
|
+
jobs = []
|
23
|
+
20.times do |i|
|
24
|
+
job = Job.new(i)
|
25
|
+
future = executor.queue(job)
|
26
|
+
jobs << future
|
27
|
+
end
|
28
|
+
jobs.each do |j|
|
29
|
+
puts "uber fast result=#{j.get}"
|
30
|
+
end
|
31
|
+
concurrent_duration = Time.now - start_time
|
32
|
+
puts "duration=" + concurrent_duration .to_s
|
33
|
+
|
34
|
+
concurrent_duration.should be < (non_concurrent_duration-2)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/job.rb
ADDED
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: concur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Travis Reeder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-02-23 00:00:00.000000000 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
description: A concurrency library for Ruby like java.util.concurrency By http://www.appoxy.com
|
16
|
+
email: travis@appoxy.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.markdown
|
21
|
+
files:
|
22
|
+
- lib/concur.rb
|
23
|
+
- lib/executor.rb
|
24
|
+
- lib/future.rb
|
25
|
+
- lib/runnable.rb
|
26
|
+
- README.markdown
|
27
|
+
- test/executor_spec.rb
|
28
|
+
- test/job.rb
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/appoxy/concur/
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.5.2
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: A concurrency library for Ruby like java.util.concurrency. By http://www.appoxy.com
|
54
|
+
test_files:
|
55
|
+
- test/executor_spec.rb
|
56
|
+
- test/job.rb
|