tpx 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tpx.rb +64 -44
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55ef407d0e8f69a4dd967da09f31116a1688c8dcd7c44402e25bca3bb1991ed8
4
- data.tar.gz: 4dba926ac28cf3f7fcd2f8f4d3bc54ea63dc16b9eb47135abc28a13a0c347b74
3
+ metadata.gz: 5187a8eb5847fc60f38bff994a70e748ae07152ff863735ef7637fa7d529d330
4
+ data.tar.gz: b5f8dc6aec4b82794016ad79716ccc03be814a3e4a8ad333138198f31462d5ae
5
5
  SHA512:
6
- metadata.gz: 4960d4130127da25b9a56303bebef1d7172d2a123a2680a9ed15f695b738b3d557c84142ccf2b87569eb11b328d4d3d81e81470b151bc53313dd1365fb9b099c
7
- data.tar.gz: bc5df89979cd7d415ec02ff79decab7cea2b69588db426fbcbd9a63428a429b300377339d2fdcd1d08a2d9fa92ec3813b4fc1d0549c19a4a6b2f842d01be5666
6
+ metadata.gz: c004ea098b906b5b81002fe9dec6e4c226e53596291ff7a732f0c8c60416e7df1c18848c1e8b00d13a14f72535d28428fd4373543b141ca858a39c9805b05675
7
+ data.tar.gz: 21da26a6a31ea133254f4d595bb467024020d79ad1900a49e40485694e068ce0b125bae840544acfd209064d9422d949280835977df235c65b31f031f20ef083
data/lib/tpx.rb CHANGED
@@ -1,60 +1,80 @@
1
- class TPX
2
-
3
- def initialize(size, opts = {})
4
- tix = opts[:tix]
5
-
6
- @size = size
7
- @jobs = Queue.new
8
-
9
- @pool = Array.new(size) do
10
- Thread.new do
11
- Thread.current[:tix] = tix if tix
12
- catch(:exit) do
13
- loop do
14
- begin
15
- jix, job, args, out = @jobs.pop
16
- out << [jix, job.call(*args)]
17
- rescue => e
18
- out << 'ERROR'
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
- def schedule(args, &block)
27
- out = Queue.new
28
- @jobs << [0, block, args, out]
29
- (out.pop)[1]
30
- end
45
+ def schedule(args, &block)
46
+ acc = Queue.new
47
+ @jobs << [0, block, args, acc]
48
+ (acc.pop)[1]
49
+ end
31
50
 
32
- def schedule_m_build
33
- Queue.new
34
- end
51
+ def schedule_m_build
52
+ Queue.new
53
+ end
35
54
 
36
- def schedule_m_add(args, &block)
37
- out = args[0]
38
- jix = args[1]
39
- args = args[2]
40
- @jobs << [jix, block, args, out]
41
- end
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
- def schedule_m_read(out, n)
44
- res = []
62
+ def schedule_m_read(acc, n)
63
+ res = []
45
64
 
46
- while res.size < n do
47
- res << (out.pop)
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
- res.sort{ |x| x[0] }
51
- end
72
+ def shutdown
73
+ @size.times do
74
+ schedule { throw :exit }
75
+ end
52
76
 
53
- def shutdown
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.1
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-10 00:00:00.000000000 Z
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.1
38
+ rubygems_version: 3.0.3
39
39
  signing_key:
40
40
  specification_version: 4
41
41
  summary: Fast Thread Pool