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 +5 -0
- data/README.md +14 -14
- data/Rakefile +1 -1
- data/lib/sync-defer.rb +15 -12
- data/sync-defer.gemspec +3 -3
- metadata +3 -3
data/CHANGES.md
CHANGED
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
|
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
data/lib/sync-defer.rb
CHANGED
@@ -17,30 +17,33 @@ module SyncDefer
|
|
17
17
|
|
18
18
|
module_function
|
19
19
|
def defer *args, &block
|
20
|
-
if
|
21
|
-
|
20
|
+
if fiber_wrapped?
|
21
|
+
if Object.const_defined?(:EventMachine) &&
|
22
|
+
EventMachine.reactor_running?
|
23
|
+
EventMachine::SyncDefer.defer(*args, &block)
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
elsif Object.const_defined?(:Coolio) &&
|
26
|
+
Coolio::Loop.default.has_active_watchers?
|
27
|
+
Coolio::SyncDefer.defer(*args, &block)
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
else
|
30
|
+
fallback("No reactor found.", *args, block)
|
31
|
+
end
|
30
32
|
|
31
33
|
else
|
32
|
-
fallback("
|
34
|
+
fallback("Not called inside a fiber.", *args, &block)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
|
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.
|
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
|
data/sync-defer.gemspec
CHANGED
@@ -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
|
+
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-
|
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.
|
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.
|
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-
|
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.
|
56
|
+
rubygems_version: 1.8.24
|
57
57
|
signing_key:
|
58
58
|
specification_version: 3
|
59
59
|
summary: Synchronous deferred operations with fibers (coroutines)
|