Narnach-future 0.1.1 → 0.2.0

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.rdoc CHANGED
@@ -6,22 +6,24 @@ value in the future. Think of asynchronous messaging and long-lasting method
6
6
  calls.
7
7
 
8
8
  An example:
9
- include Future
10
- f = future { sleep 5; 123}
11
- puts f * 5
12
- The future will take 5 seconds to run, then 123 is returned.
9
+ f = Future.new { sleep 5; 123}
10
+ puts f * 5 #=> 615
11
+ Theis future will take 5 seconds to run, then 123 is returned.
13
12
  The call f.*(5) will block until the future is done.
14
13
 
15
14
  Another example:
16
- include Future
17
- f1 = future { sleep 5; 10}
18
- f2 = future { sleep 3; 20}
19
- f3 = future { sleep 1; 30}
15
+ f1 = Future.new { sleep 5; 10}
16
+ f2 = Future.new { sleep 3; 20}
17
+ f3 = Future.new { sleep 1; 30}
20
18
  puts f3 + f2 + f1
21
19
  Here it only takes 5 seconds to calculate the sum instead of the 9 it would take when done sequentially.
22
20
 
23
21
  == Recent changes
24
22
 
23
+ === Version 0.2.0
24
+ * Replaced Future Module with Future class. The old syntax is no longer supported.
25
+ * Replaced one-time use of eval with undef_method.
26
+
25
27
  === Version 0.1.1
26
28
  * Added specs
27
29
 
data/future.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.name = 'future'
4
4
  s.summary = "A naieve implementation of futures"
5
5
  s.description = "A naieve implementation of futures"
6
- s.version = '0.1.1'
7
- s.date = '2008-12-08'
6
+ s.version = '0.2.0'
7
+ s.date = '2008-12-10'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Wes Oldenbeuving"]
10
10
  s.email = "narnach@gmail.com"
data/lib/future.rb CHANGED
@@ -4,30 +4,27 @@
4
4
  # calls.
5
5
  #
6
6
  # An example:
7
- # include Future
8
- # f = future { sleep 5; 123}
7
+ # f = Future.new { sleep 5; 123}
9
8
  # puts f * 5 #=> 615
10
- # The future will take 5 seconds to run, then 123 is returned.
9
+ # Theis future will take 5 seconds to run, then 123 is returned.
11
10
  # The call f.*(5) will block until the future is done.
12
11
  #
13
12
  # Another example:
14
- # include Future
15
- # f1 = future { sleep 5; 10}
16
- # f2 = future { sleep 3; 20}
17
- # f3 = future { sleep 1; 30}
13
+ # f1 = Future.new { sleep 5; 10}
14
+ # f2 = Future.new { sleep 3; 20}
15
+ # f3 = Future.new { sleep 1; 30}
18
16
  # puts f3 + f2 + f1
19
17
  # Here it only takes 5 seconds to calculate the sum instead of the 9 it would take when done sequentially.
20
- module Future
21
- def future(&block)
22
- t = Thread.new(&block)
23
- class << t
24
- (instance_methods - %w[value __send__ __id__]).each do |meth|
25
- eval("undef #{meth}")
26
- end
27
- def method_missing(*args, &block)
28
- value.send(*args,&block)
29
- end
30
- end
31
- t
18
+ class Future
19
+ (instance_methods - %w[__send__ __id__ object_id]).each do |meth|
20
+ undef_method meth
21
+ end
22
+
23
+ def initialize(&block)
24
+ @thread = Thread.new(&block)
25
+ end
26
+
27
+ def method_missing(*args, &block)
28
+ @thread.value.send(*args,&block)
32
29
  end
33
30
  end
data/spec/future_spec.rb CHANGED
@@ -1,25 +1,19 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
  require 'future'
3
3
 
4
- class TimeTraveller
5
- include Future
6
- end
7
-
8
- describe Future, '#future' do
4
+ describe Future, '.new' do
9
5
  it 'should return the return value of the block' do
10
- tt = TimeTraveller.new
11
- f1 = tt.future { 10 }
12
- f2 = tt.future { 20 }
13
- f3 = tt.future { 30 }
6
+ f1 = Future.new { 10 }
7
+ f2 = Future.new { 20 }
8
+ f3 = Future.new { 30 }
14
9
  (f3 + f2 + f1).should == 60
15
10
  end
16
11
 
17
12
  it 'should execute futures in parallel' do
18
- tt = TimeTraveller.new
19
13
  now = Time.now
20
- f1 = tt.future { sleep 0.2; 10 }
21
- f2 = tt.future { sleep 0.1; 20 }
22
- f3 = tt.future { 30 }
14
+ f1 = Future.new { sleep 0.2; 10 }
15
+ f2 = Future.new { sleep 0.1; 20 }
16
+ f3 = Future.new { 30 }
23
17
  f3+f2+f1
24
18
  diff = Time.now - now
25
19
  diff.should < 0.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Narnach-future
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Oldenbeuving
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-08 00:00:00 -08:00
12
+ date: 2008-12-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15