gb_dispatch 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +2 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +22 -6
- data/gb_dispatch.gemspec +1 -1
- data/lib/gb_dispatch/manager.rb +6 -3
- data/lib/gb_dispatch/queue.rb +14 -3
- data/lib/gb_dispatch/runner.rb +1 -1
- data/lib/gb_dispatch/version.rb +1 -1
- data/lib/gb_dispatch.rb +5 -9
- data/spec/dispatch_spec.rb +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd041feeb927183160d8026c38344e6613eb2732
|
4
|
+
data.tar.gz: 64288309c1cace61a076ab1adee82d2a9ef41912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 768ca64392814c1b0a72a9bef66e0114242f4fcb08d5b412e8665aa8bc8e26771d299909bcaf388e8e1717e36a92afb6025f667cd6728010713e117d2ed68554
|
7
|
+
data.tar.gz: 5f412a4ae3d9cdd91f3c3cf50130b206049adf6e426736700ec58ab6cfe0c79b3867008d905bc24fb7e93fb349f1babeafb72af4b3a7ddf074c69fe42dbcf4f5
|
data/CHANGELOG.txt
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gb_dispatch (0.0.
|
5
|
-
celluloid (~> 0.
|
4
|
+
gb_dispatch (0.0.4)
|
5
|
+
celluloid (~> 0.17.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
celluloid (0.
|
11
|
-
|
10
|
+
celluloid (0.17.3)
|
11
|
+
celluloid-essentials
|
12
|
+
celluloid-extras
|
13
|
+
celluloid-fsm
|
14
|
+
celluloid-pool
|
15
|
+
celluloid-supervision
|
16
|
+
timers (>= 4.1.1)
|
17
|
+
celluloid-essentials (0.20.5)
|
18
|
+
timers (>= 4.1.1)
|
19
|
+
celluloid-extras (0.20.5)
|
20
|
+
timers (>= 4.1.1)
|
21
|
+
celluloid-fsm (0.20.5)
|
22
|
+
timers (>= 4.1.1)
|
23
|
+
celluloid-pool (0.20.5)
|
24
|
+
timers (>= 4.1.1)
|
25
|
+
celluloid-supervision (0.20.5)
|
26
|
+
timers (>= 4.1.1)
|
12
27
|
diff-lcs (1.2.5)
|
13
28
|
docile (1.1.5)
|
29
|
+
hitimes (1.2.3)
|
14
30
|
json (1.8.3)
|
15
31
|
rake (10.5.0)
|
16
32
|
rspec (3.4.0)
|
@@ -31,14 +47,14 @@ GEM
|
|
31
47
|
json (~> 1.8)
|
32
48
|
simplecov-html (~> 0.10.0)
|
33
49
|
simplecov-html (0.10.0)
|
34
|
-
timers (1.1
|
50
|
+
timers (4.1.1)
|
51
|
+
hitimes
|
35
52
|
|
36
53
|
PLATFORMS
|
37
54
|
ruby
|
38
55
|
|
39
56
|
DEPENDENCIES
|
40
57
|
bundler (~> 1.6)
|
41
|
-
celluloid (~> 0.15.2)
|
42
58
|
gb_dispatch!
|
43
59
|
rake (~> 10.0)
|
44
60
|
rspec
|
data/gb_dispatch.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'celluloid', '~> 0.
|
21
|
+
spec.add_dependency 'celluloid', '~> 0.17.3'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
data/lib/gb_dispatch/manager.rb
CHANGED
@@ -14,12 +14,12 @@ module GBDispatch
|
|
14
14
|
# Remember that for each allocated queue, there is new thread allocated.
|
15
15
|
# @param name [String, Symbol] if not passed, default queue will be returned.
|
16
16
|
# @return [GBDispatch::Queue]
|
17
|
-
def get_queue(name=:
|
17
|
+
def get_queue(name=:default_queue)
|
18
18
|
name = name.to_sym
|
19
19
|
queue = Celluloid::Actor[name]
|
20
20
|
unless queue
|
21
|
-
|
22
|
-
queue =
|
21
|
+
Queue.supervise as: name, args: [name, @pool]
|
22
|
+
queue = Celluloid::Actor[name]
|
23
23
|
end
|
24
24
|
queue
|
25
25
|
end
|
@@ -36,6 +36,7 @@ module GBDispatch
|
|
36
36
|
# puts 'Delayed Hello World!'
|
37
37
|
# end
|
38
38
|
def run_async_on_queue(queue)
|
39
|
+
raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue
|
39
40
|
queue.async.perform ->() { yield }
|
40
41
|
end
|
41
42
|
|
@@ -52,6 +53,7 @@ module GBDispatch
|
|
52
53
|
# 42
|
53
54
|
# end
|
54
55
|
def run_sync_on_queue(queue)
|
56
|
+
raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue
|
55
57
|
future = queue.future.perform ->() { yield }
|
56
58
|
future.value
|
57
59
|
end
|
@@ -67,6 +69,7 @@ module GBDispatch
|
|
67
69
|
# end
|
68
70
|
#
|
69
71
|
def run_after_on_queue(time, queue)
|
72
|
+
raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue
|
70
73
|
queue.perform_after time, ->(){ yield }
|
71
74
|
end
|
72
75
|
|
data/lib/gb_dispatch/queue.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'celluloid'
|
1
|
+
require 'celluloid/current'
|
2
2
|
module GBDispatch
|
3
3
|
class Queue
|
4
4
|
include Celluloid
|
@@ -11,6 +11,7 @@ module GBDispatch
|
|
11
11
|
def initialize(name, thread_pool)
|
12
12
|
@name = name
|
13
13
|
@thread_pool = thread_pool
|
14
|
+
@executing = false
|
14
15
|
end
|
15
16
|
|
16
17
|
# Perform given block
|
@@ -34,13 +35,19 @@ module GBDispatch
|
|
34
35
|
else
|
35
36
|
thread_block = block ? block : ->() { yield }
|
36
37
|
end
|
37
|
-
|
38
|
+
while @executing
|
39
|
+
sleep(0.0001)
|
40
|
+
end
|
41
|
+
#exclusive do
|
38
42
|
begin
|
43
|
+
@executing = true
|
39
44
|
@thread_pool.execute thread_block, name: name
|
40
45
|
rescue Exception => e
|
41
46
|
return e
|
47
|
+
ensure
|
48
|
+
@executing = false
|
42
49
|
end
|
43
|
-
end
|
50
|
+
#end
|
44
51
|
end
|
45
52
|
|
46
53
|
# Perform block after given period
|
@@ -53,5 +60,9 @@ module GBDispatch
|
|
53
60
|
self.async.perform block
|
54
61
|
end
|
55
62
|
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
self.name.to_s
|
66
|
+
end
|
56
67
|
end
|
57
68
|
end
|
data/lib/gb_dispatch/runner.rb
CHANGED
data/lib/gb_dispatch/version.rb
CHANGED
data/lib/gb_dispatch.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gb_dispatch/version'
|
2
2
|
require 'gb_dispatch/manager'
|
3
|
-
|
3
|
+
|
4
4
|
|
5
5
|
# Library to dispatch block on queues.
|
6
6
|
# It is inspired by GCD but implementation is based on Celluloid.
|
@@ -24,7 +24,7 @@ module GBDispatch
|
|
24
24
|
# @param queue [Symbol, GBDispatch::Queue] queue object or name
|
25
25
|
# @yield block to execute
|
26
26
|
def self.dispatch_async(queue)
|
27
|
-
queue =
|
27
|
+
queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
|
28
28
|
GBDispatch::Manager.instance.run_async_on_queue queue do
|
29
29
|
yield
|
30
30
|
end
|
@@ -34,7 +34,7 @@ module GBDispatch
|
|
34
34
|
# @param queue [Symbol, GBDispatch::Queue] queue object or name
|
35
35
|
# @yield block to execute
|
36
36
|
def self.dispatch_sync(queue)
|
37
|
-
queue =
|
37
|
+
queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
|
38
38
|
GBDispatch::Manager.instance.run_sync_on_queue queue do
|
39
39
|
yield
|
40
40
|
end
|
@@ -46,8 +46,8 @@ module GBDispatch
|
|
46
46
|
# @param queue [Symbol, GBDispatch::Queue] queue object or name
|
47
47
|
# @yield block to execute
|
48
48
|
def self.dispatch_after(delay, queue)
|
49
|
-
queue =
|
50
|
-
GBDispatch::Manager.instance.
|
49
|
+
queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
|
50
|
+
GBDispatch::Manager.instance.run_after_on_queue delay, queue do
|
51
51
|
yield
|
52
52
|
end
|
53
53
|
end
|
@@ -64,8 +64,4 @@ module GBDispatch
|
|
64
64
|
alias_method :dispatch_async_on_queue, :dispatch_async
|
65
65
|
alias_method :dispatch_after_on_queue, :dispatch_after
|
66
66
|
end
|
67
|
-
|
68
|
-
at_exit do
|
69
|
-
GBDispatch::Manager.instance.exit
|
70
|
-
end
|
71
67
|
end
|
data/spec/dispatch_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe GBDispatch do
|
|
13
13
|
a << 2
|
14
14
|
end
|
15
15
|
expect(a.empty?).to be_truthy
|
16
|
-
sleep(0.
|
16
|
+
sleep(0.03)
|
17
17
|
expect(a).to eq [1, 2]
|
18
18
|
end
|
19
19
|
|
@@ -73,13 +73,13 @@ describe GBDispatch do
|
|
73
73
|
a << 1
|
74
74
|
end
|
75
75
|
expect(a.empty?).to be_truthy
|
76
|
-
sleep(0.
|
76
|
+
sleep(0.2)
|
77
77
|
expect(a).to eq [1]
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should return proper queue' do
|
81
81
|
queue = GBDispatch.get_queue :test
|
82
|
-
expect(queue.name).to eq :test
|
83
82
|
expect(queue).to be_a GBDispatch::Queue
|
83
|
+
expect(queue.name).to eq :test
|
84
84
|
end
|
85
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gb_dispatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kacper Kawecki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.17.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.17.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.5.1
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: GCD emulation for ruby
|