tpx 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/tpx.rb +60 -0
  3. metadata +42 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55ef407d0e8f69a4dd967da09f31116a1688c8dcd7c44402e25bca3bb1991ed8
4
+ data.tar.gz: 4dba926ac28cf3f7fcd2f8f4d3bc54ea63dc16b9eb47135abc28a13a0c347b74
5
+ SHA512:
6
+ metadata.gz: 4960d4130127da25b9a56303bebef1d7172d2a123a2680a9ed15f695b738b3d557c84142ccf2b87569eb11b328d4d3d81e81470b151bc53313dd1365fb9b099c
7
+ data.tar.gz: bc5df89979cd7d415ec02ff79decab7cea2b69588db426fbcbd9a63428a429b300377339d2fdcd1d08a2d9fa92ec3813b4fc1d0549c19a4a6b2f842d01be5666
data/lib/tpx.rb ADDED
@@ -0,0 +1,60 @@
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'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def schedule(args, &block)
27
+ out = Queue.new
28
+ @jobs << [0, block, args, out]
29
+ (out.pop)[1]
30
+ end
31
+
32
+ def schedule_m_build
33
+ Queue.new
34
+ end
35
+
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
42
+
43
+ def schedule_m_read(out, n)
44
+ res = []
45
+
46
+ while res.size < n do
47
+ res << (out.pop)
48
+ end
49
+
50
+ res.sort{ |x| x[0] }
51
+ end
52
+
53
+ def shutdown
54
+ @size.times do
55
+ schedule { throw :exit }
56
+ end
57
+
58
+ @pool.map(&:join)
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tpx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - bfx devs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Fast Thread Pool
14
+ email: paolo@bitfinex.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/tpx.rb
20
+ homepage: https://www.bitfinex.com
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubygems_version: 3.0.1
39
+ signing_key:
40
+ specification_version: 4
41
+ summary: Fast Thread Pool
42
+ test_files: []