myna_eventmachine 1.1.0 → 1.1.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.md CHANGED
@@ -46,5 +46,4 @@ Rake commands:
46
46
 
47
47
  ## TODO
48
48
 
49
- - Futures need to handle failures, and need to rigourously trap exceptions and propagate them.
50
49
  - Some RDoc or equivalent might be useful
data/lib/myna/future.rb CHANGED
@@ -27,9 +27,9 @@ require 'thread'
27
27
 
28
28
  module Future
29
29
 
30
- def Future.run
30
+ def Future.run(&block)
31
31
  future = Future.new
32
- future.run(yield)
32
+ future.run(block)
33
33
  future
34
34
  end
35
35
 
@@ -68,9 +68,10 @@ module Future
68
68
  self.set(value, :failure)
69
69
  end
70
70
 
71
- def run
71
+ def run(proc)
72
72
  begin
73
- self.succeed(yield)
73
+ value = proc.call()
74
+ self.succeed(value)
74
75
  rescue => exn
75
76
  self.fail(exn)
76
77
  end
@@ -120,9 +121,7 @@ module Future
120
121
  def map(&block)
121
122
  future = Future.new
122
123
  self.on_complete do |value|
123
- future.run do
124
- block.call(value)
125
- end
124
+ future.run(proc { block.call(value) })
126
125
  end
127
126
  future
128
127
  end
data/lib/myna/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  #
24
24
 
25
25
  module Myna
26
- VERSION = "1.1.0"
26
+ VERSION = "1.1.1"
27
27
  end
data/test/test_future.rb CHANGED
@@ -54,9 +54,23 @@ describe Future do
54
54
 
55
55
  describe "Future.fail" do
56
56
  it "must cause an exception to be raised on get" do
57
- # Not implemented
58
- # Also test Future.run and future.run
59
- true.must_equal false
57
+ exn = Exception.new("A test")
58
+ f = Future::Future.new
59
+ f.fail(exn)
60
+
61
+ proc { f.get }.must_raise Exception
62
+ end
63
+ end
64
+
65
+ describe "Future.run" do
66
+ it "must complete the future with the expected value" do
67
+ f = Future.run do 1 + 1 end
68
+ f.get.must_equal 2
69
+ end
70
+
71
+ it "must catch exceptions and complete the future in a failed state" do
72
+ f = Future.run do 1/0 end
73
+ proc { f.get }.must_raise ZeroDivisionError
60
74
  end
61
75
  end
62
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myna_eventmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: