rhinothread 1.0.0
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 +7 -0
- data/lib/rhinothread.rb +86 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52c3f3fcf4d93e97cee71defd7ad244e26a187b3
|
4
|
+
data.tar.gz: 4ff716709abcf44139dd94db7f8c177555c9742a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 421f275fc98ea9868764b4ea1958bb8aafa86b54b9b40ba7d528ac2c1eded07d371b9e85693d85a5730e30fdda350502018c47ed574dc04871f1673665ac26da
|
7
|
+
data.tar.gz: 23f212fc0a006a2ff61e6eed776c883e1823bc9d78b7784299e3b22c19e1af6d8676346e9c594b045f00ba2a558cd34cdbe719bea638c774c3527e6afb16be8b
|
data/lib/rhinothread.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
class RhinoThread
|
2
|
+
|
3
|
+
# New Instance
|
4
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
5
|
+
def initialize limit
|
6
|
+
|
7
|
+
@threads = []
|
8
|
+
@queue = []
|
9
|
+
@on = true
|
10
|
+
@limit = limit
|
11
|
+
|
12
|
+
end
|
13
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
14
|
+
|
15
|
+
|
16
|
+
# Store a block of code
|
17
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
18
|
+
def queue &block
|
19
|
+
|
20
|
+
@queue << block
|
21
|
+
|
22
|
+
end
|
23
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
24
|
+
|
25
|
+
|
26
|
+
# Run everything
|
27
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
28
|
+
def execute
|
29
|
+
|
30
|
+
StartThreads()
|
31
|
+
|
32
|
+
end
|
33
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
34
|
+
|
35
|
+
|
36
|
+
# Start the first(@limit) threads
|
37
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
38
|
+
def StartThreads()
|
39
|
+
|
40
|
+
@limit = @queue.count if @limit >= @queue.count
|
41
|
+
@limit.times do |i|
|
42
|
+
|
43
|
+
NewThread()
|
44
|
+
|
45
|
+
end
|
46
|
+
JoinThreads()
|
47
|
+
|
48
|
+
end
|
49
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
50
|
+
|
51
|
+
|
52
|
+
# Join Threads
|
53
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
54
|
+
def JoinThreads()
|
55
|
+
|
56
|
+
@threads.each do |aThread|
|
57
|
+
|
58
|
+
if aThread.join
|
59
|
+
|
60
|
+
NewThread() if @threads.count < @queue.count && @on
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
68
|
+
|
69
|
+
|
70
|
+
# Execute each thread
|
71
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
72
|
+
def NewThread()
|
73
|
+
|
74
|
+
tCount = @threads.count
|
75
|
+
@threads << Thread.new(tCount) do |tNum|
|
76
|
+
|
77
|
+
@queue[tNum].call
|
78
|
+
|
79
|
+
Thread.exit
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
# -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
|
85
|
+
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhinothread
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wambl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple way to limit a queue of threads.
|
14
|
+
email: will@wambl.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rhinothread.rb
|
20
|
+
homepage: http://rubygems.org/gems/rhinothread
|
21
|
+
licenses:
|
22
|
+
- Wambl
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Multithread Limiter
|
44
|
+
test_files: []
|