sync-defer 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # CHANGES
2
2
 
3
+ ## sync-defer 0.9.3 -- 2012-03-20
4
+
5
+ * Also work without a reactor in the generic interface: `SyncDefer.defer`,
6
+ but print a warning about it.
7
+
3
8
  ## sync-defer 0.9.2 -- 2012-03-20
4
9
 
5
10
  * Properly select the reactor.
6
11
 
7
- * Make it exception aware. If there's an exception raised in the
12
+ * Made it exception aware. If there's an exception raised in the
8
13
  computation, sync-defer would resume back and raise that exception.
9
14
 
10
15
  ## sync-defer 0.9.1 -- 2012-02-25
data/README.md CHANGED
@@ -25,69 +25,70 @@ Synchronous deferred operations with fibers (coroutines)
25
25
 
26
26
  Remember to wrap a fiber around the client, and inside the client:
27
27
 
28
- ### Generic interface which would select underneath reactor automatically:
29
-
30
- ``` ruby
31
- # Single computation:
32
- puts(SyncDefer.defer{
33
- sleep(10) # any CPU-bound operations
34
- 100}) # 100
35
- puts "DONE"
36
-
37
- # Multiple computations:
38
- puts(SyncDefer.defer(lambda{
39
- sleep(10) # any CPU-bound operations
40
- 100
41
- },
42
- lambda{
43
- sleep(5) # any CPU-bound operations
44
- 50})) # [100, 50] # it would match the index
45
- puts "DONE"
46
- ```
47
-
48
- Full examples with reactor turned on:
49
-
50
- ### with cool.io:
51
-
52
- ``` ruby
53
- # only for adding at least one watcher in the loop
54
- Coolio::TimerWatcher.new(1).attach(Coolio::Loop.default).on_timer{detach}
55
-
56
- Fiber.new{
57
- # or Coolio::SyncDefer
58
- SyncDefer.defer{ sleep(10) }
28
+ * Generic interface which would select underneath reactor automatically:
29
+
30
+ ``` ruby
31
+ # Single computation:
32
+ puts(SyncDefer.defer{
33
+ sleep(5) # any CPU-bound operations
34
+ 100}) # 100
59
35
  puts "DONE"
60
- }.resume
61
- Coolio::Loop.default.run
62
- ```
63
36
 
64
- ### with eventmachine:
37
+ # Multiple computations:
38
+ puts(SyncDefer.defer(lambda{
39
+ sleep(5) # any CPU-bound operations
40
+ 100
41
+ },
42
+ lambda{
43
+ sleep(2) # any CPU-bound operations
44
+ 50})) # [100, 50] # it would match the index
45
+ puts "DONE"
46
+ ```
65
47
 
66
- ``` ruby
67
- EM.run{
68
- Fiber.new{
69
- # or EM::SyncDefer
70
- SyncDefer.defer{ sleep(10) }
71
- puts "DONE"
72
- EM.stop
73
- }.resume
74
- }
75
- ```
48
+ Full examples with reactor turned on:
49
+
50
+ * with cool.io:
76
51
 
77
- ### No problems with exceptions, use them as normal:
52
+ ``` ruby
53
+ # only for adding at least one watcher in the loop
54
+ Coolio::TimerWatcher.new(1).
55
+ attach(Coolio::Loop.default).on_timer{detach}
78
56
 
79
- ``` ruby
80
- EM.run{
81
57
  Fiber.new{
82
- begin
83
- SyncDefer.defer{ raise "BOOM" }
84
- rescue => e
85
- p e
86
- end
87
- EM.stop
58
+ # or Coolio::SyncDefer
59
+ SyncDefer.defer{ sleep(5) }
60
+ puts "DONE"
88
61
  }.resume
89
- }
90
- ```
62
+ Coolio::Loop.default.run
63
+ ```
64
+
65
+ * with eventmachine:
66
+
67
+ ``` ruby
68
+ EM.run{
69
+ Fiber.new{
70
+ # or EM::SyncDefer
71
+ SyncDefer.defer{ sleep(5) }
72
+ puts "DONE"
73
+ EM.stop
74
+ }.resume
75
+ }
76
+ ```
77
+
78
+ * No problems with exceptions, use them as normal:
79
+
80
+ ``` ruby
81
+ EM.run{
82
+ Fiber.new{
83
+ begin
84
+ SyncDefer.defer{ raise "BOOM" }
85
+ rescue => e
86
+ p e
87
+ end
88
+ EM.stop
89
+ }.resume
90
+ }
91
+ ```
91
92
 
92
93
  ## CONTRIBUTORS:
93
94
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ desc 'Generate gemspec'
8
8
  task 'gem:spec' do
9
9
  Gemgem.spec = Gemgem.create do |s|
10
10
  s.name = 'sync-defer'
11
- s.version = '0.9.2'
11
+ s.version = '0.9.3'
12
12
 
13
13
  %w[].each{ |g| s.add_runtime_dependency(g) }
14
14
  end
data/lib/sync-defer.rb CHANGED
@@ -18,7 +18,11 @@ module SyncDefer
18
18
  Coolio::Loop.default.has_active_watchers?
19
19
  Coolio::SyncDefer.defer(*args, &block)
20
20
  else
21
- raise "No reactor found. Only cool.io and eventmachine are supported."
21
+ $stderr.puts("SyncDefer: WARN: No reactor found. " \
22
+ "Only cool.io and eventmachine are supported.")
23
+ $stderr.puts(" Called from: #{caller.last(5).inspect}")
24
+ args << block if block_given?
25
+ args.map(&:call)
22
26
  end
23
27
  end
24
28
  end
data/sync-defer.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sync-defer"
5
- s.version = "0.9.2"
5
+ s.version = "0.9.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
@@ -15,8 +15,8 @@ begin
15
15
  [Coolio::SyncDefer, SyncDefer].each do |defer|
16
16
  describe defer do
17
17
  before do
18
- stub(Object).const_defined?(:EventMachine){ false }
19
- stub(Object).const_defined?(:Coolio) { true }
18
+ @watcher = Coolio::AsyncWatcher.new.attach(Coolio::Loop.default)
19
+ @watcher.on_signal{detach}
20
20
  end
21
21
 
22
22
  after do
@@ -29,6 +29,7 @@ begin
29
29
  result << defer.defer{ sleep 0.1; result << 0; 1 }
30
30
  result << defer.defer(lambda{ 2 })
31
31
  result << 3
32
+ @watcher.signal
32
33
  }.resume
33
34
  Coolio::Loop.default.run
34
35
  result.should.eql [0, 1, 2, 3]
@@ -40,6 +41,7 @@ begin
40
41
  result.concat(defer.defer(lambda{ sleep 0.1; 1 },
41
42
  lambda{ result << 0; 2 }))
42
43
  result << 3
44
+ @watcher.signal
43
45
  }.resume
44
46
  Coolio::Loop.default.run
45
47
  result.should.eql [0, 1, 2, 3]
@@ -50,6 +52,7 @@ begin
50
52
  lambda{
51
53
  defer.defer{ raise TestException }
52
54
  }.should.raise(TestException)
55
+ @watcher.signal
53
56
  }.resume
54
57
  Coolio::Loop.default.run
55
58
  end
@@ -63,6 +66,7 @@ begin
63
66
  lambda{
64
67
  defer.defer(lambda{}, lambda{ raise TestException })
65
68
  }.should.raise(TestException)
69
+ @watcher.signal
66
70
  }.resume
67
71
  Coolio::Loop.default.run
68
72
  end
@@ -76,10 +80,6 @@ begin
76
80
  require 'eventmachine/sync-defer'
77
81
  [EventMachine::SyncDefer, SyncDefer].each do |defer|
78
82
  describe defer do
79
- before do
80
- stub(Object).const_defined?(:EventMachine){ true }
81
- end
82
-
83
83
  after do
84
84
  RR.verify
85
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync-defer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: