sync-defer 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGES
2
2
 
3
+ ## sync-defer 0.9.6 -- 2012-09-13
4
+
5
+ * Fixed call stacks information in the warning.
6
+ * Properly detect if we're inside a fiber.
7
+
3
8
  ## sync-defer 0.9.5 -- 2012-03-21
4
9
 
5
10
  * Also fall back whenever it's not wrapped inside a fiber.
data/README.md CHANGED
@@ -14,7 +14,7 @@ Synchronous deferred operations with fibers (coroutines)
14
14
 
15
15
  ## REQUIREMENTS:
16
16
 
17
- * Either cool.io or eventmachine
17
+ * Either eventmachine or cool.io
18
18
  * Ruby 1.9+ (or if fibers could be used in Ruby 1.8)
19
19
 
20
20
  ## INSTALLATION:
@@ -47,6 +47,19 @@ Remember to wrap a fiber around the client, and inside the client:
47
47
 
48
48
  Full examples with reactor turned on:
49
49
 
50
+ * with eventmachine:
51
+
52
+ ``` ruby
53
+ EM.run{
54
+ Fiber.new{
55
+ # or EM::SyncDefer
56
+ SyncDefer.defer{ sleep(5) }
57
+ puts "DONE"
58
+ EM.stop
59
+ }.resume
60
+ }
61
+ ```
62
+
50
63
  * with cool.io:
51
64
 
52
65
  ``` ruby
@@ -62,19 +75,6 @@ Remember to wrap a fiber around the client, and inside the client:
62
75
  Coolio::Loop.default.run
63
76
  ```
64
77
 
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
78
  * No problems with exceptions, use them as normal:
79
79
 
80
80
  ``` ruby
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.5'
11
+ s.version = '0.9.6'
12
12
 
13
13
  %w[].each{ |g| s.add_runtime_dependency(g) }
14
14
  end
@@ -17,30 +17,33 @@ module SyncDefer
17
17
 
18
18
  module_function
19
19
  def defer *args, &block
20
- if root_fiber?
21
- fallback("Not called inside a fiber.", *args, &block)
20
+ if fiber_wrapped?
21
+ if Object.const_defined?(:EventMachine) &&
22
+ EventMachine.reactor_running?
23
+ EventMachine::SyncDefer.defer(*args, &block)
22
24
 
23
- elsif Object.const_defined?(:EventMachine) &&
24
- EventMachine.reactor_running?
25
- EventMachine::SyncDefer.defer(*args, &block)
25
+ elsif Object.const_defined?(:Coolio) &&
26
+ Coolio::Loop.default.has_active_watchers?
27
+ Coolio::SyncDefer.defer(*args, &block)
26
28
 
27
- elsif Object.const_defined?(:Coolio) &&
28
- Coolio::Loop.default.has_active_watchers?
29
- Coolio::SyncDefer.defer(*args, &block)
29
+ else
30
+ fallback("No reactor found.", *args, block)
31
+ end
30
32
 
31
33
  else
32
- fallback("No reactor found.", *args, block)
34
+ fallback("Not called inside a fiber.", *args, &block)
33
35
  end
34
36
  end
35
37
 
36
- def root_fiber?
37
- RootFiber == Fiber.current
38
+ def fiber_wrapped?
39
+ # because under a thread, Fiber.current won't return the root fiber
40
+ RootFiber != Fiber.current && Thread.main == Thread.current
38
41
  end
39
42
 
40
43
  def fallback message, *args, &block
41
44
  $stderr.puts("SyncDefer: WARN: #{message}")
42
45
  $stderr.puts(" Falling back to run the computation directly.")
43
- $stderr.puts(" Called from: #{caller.last(5).inspect}")
46
+ $stderr.puts(" Called from: #{caller.first(5).inspect}")
44
47
  args << block if block_given?
45
48
  if args.size == 1
46
49
  args.first.call
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sync-defer"
5
- s.version = "0.9.5"
5
+ s.version = "0.9.6"
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)"]
9
- s.date = "2012-03-21"
9
+ s.date = "2012-09-13"
10
10
  s.description = "Synchronous deferred operations with fibers (coroutines)"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.files = [
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  "test/test_sync-defer.rb"]
28
28
  s.homepage = "https://github.com/godfat/sync-defer"
29
29
  s.require_paths = ["lib"]
30
- s.rubygems_version = "1.8.19"
30
+ s.rubygems_version = "1.8.24"
31
31
  s.summary = "Synchronous deferred operations with fibers (coroutines)"
32
32
  s.test_files = ["test/test_sync-defer.rb"]
33
33
 
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.5
4
+ version: 0.9.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000 Z
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Synchronous deferred operations with fibers (coroutines)
15
15
  email:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 1.8.19
56
+ rubygems_version: 1.8.24
57
57
  signing_key:
58
58
  specification_version: 3
59
59
  summary: Synchronous deferred operations with fibers (coroutines)