tpx 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tpx.rb +64 -44
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5187a8eb5847fc60f38bff994a70e748ae07152ff863735ef7637fa7d529d330
|
4
|
+
data.tar.gz: b5f8dc6aec4b82794016ad79716ccc03be814a3e4a8ad333138198f31462d5ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c004ea098b906b5b81002fe9dec6e4c226e53596291ff7a732f0c8c60416e7df1c18848c1e8b00d13a14f72535d28428fd4373543b141ca858a39c9805b05675
|
7
|
+
data.tar.gz: 21da26a6a31ea133254f4d595bb467024020d79ad1900a49e40485694e068ce0b125bae840544acfd209064d9422d949280835977df235c65b31f031f20ef083
|
data/lib/tpx.rb
CHANGED
@@ -1,60 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
module TPX
|
2
|
+
class Prom
|
3
|
+
def initialize(exec)
|
4
|
+
@cnt = 0
|
5
|
+
@exec = exec
|
6
|
+
@q = exec.schedule_m_build
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(args, &block)
|
10
|
+
@exec.schedule_m_add([@q, @cnt, args], &block)
|
11
|
+
@cnt += 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def resolve
|
15
|
+
res = @exec.schedule_m_read(@q, @cnt)
|
16
|
+
res.map{ |a| a[1] }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Exec
|
21
|
+
|
22
|
+
def initialize(size, opts = {})
|
23
|
+
tix = opts[:tix]
|
24
|
+
|
25
|
+
@size = size
|
26
|
+
@jobs = Queue.new
|
27
|
+
|
28
|
+
@pool = Array.new(size) do
|
29
|
+
Thread.new do
|
30
|
+
Thread.current[:tix] = tix if tix
|
31
|
+
catch(:exit) do
|
32
|
+
loop do
|
33
|
+
begin
|
34
|
+
jix, job, args, acc = @jobs.pop
|
35
|
+
acc << [jix, job.call(*args)]
|
36
|
+
rescue => e
|
37
|
+
acc << 'ERROR'
|
38
|
+
end
|
19
39
|
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
23
43
|
end
|
24
|
-
end
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
45
|
+
def schedule(args, &block)
|
46
|
+
acc = Queue.new
|
47
|
+
@jobs << [0, block, args, acc]
|
48
|
+
(acc.pop)[1]
|
49
|
+
end
|
31
50
|
|
32
|
-
|
33
|
-
|
34
|
-
|
51
|
+
def schedule_m_build
|
52
|
+
Queue.new
|
53
|
+
end
|
35
54
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
55
|
+
def schedule_m_add(args, &block)
|
56
|
+
acc = args[0]
|
57
|
+
jix = args[1]
|
58
|
+
args = args[2]
|
59
|
+
@jobs << [jix, block, args, acc]
|
60
|
+
end
|
42
61
|
|
43
|
-
|
44
|
-
|
62
|
+
def schedule_m_read(acc, n)
|
63
|
+
res = []
|
45
64
|
|
46
|
-
|
47
|
-
|
65
|
+
while res.size < n do
|
66
|
+
res << (acc.pop)
|
67
|
+
end
|
68
|
+
|
69
|
+
res.sort{ |x| x[0] }
|
48
70
|
end
|
49
71
|
|
50
|
-
|
51
|
-
|
72
|
+
def shutdown
|
73
|
+
@size.times do
|
74
|
+
schedule { throw :exit }
|
75
|
+
end
|
52
76
|
|
53
|
-
|
54
|
-
@size.times do
|
55
|
-
schedule { throw :exit }
|
77
|
+
@pool.map(&:join)
|
56
78
|
end
|
57
|
-
|
58
|
-
@pool.map(&:join)
|
59
79
|
end
|
60
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tpx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bfx devs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fast Thread Pool
|
14
14
|
email: paolo@bitfinex.com
|
@@ -35,7 +35,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '0'
|
37
37
|
requirements: []
|
38
|
-
rubygems_version: 3.0.
|
38
|
+
rubygems_version: 3.0.3
|
39
39
|
signing_key:
|
40
40
|
specification_version: 4
|
41
41
|
summary: Fast Thread Pool
|