xthreads 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f12aebb9b3bb9a03f0ecb3c71f7a1605645d17a9
4
- data.tar.gz: 513c15f68d0742d07521e05cdb99f6743c406e7b
3
+ metadata.gz: f8c98c4a33d5f7aa33c2d826ba625f1df19a417c
4
+ data.tar.gz: 7b77ac05e3fa220cf25def980725d87b2994a28d
5
5
  SHA512:
6
- metadata.gz: bf9547f3d4ab42e9dee2d69ec0461b9698181ba0c41d88ac78574bfd6c48f24d551528aadb9a148017572cddc03111778cbb9df61c63396fa23143561131efce
7
- data.tar.gz: 754767bc4d9546757139824a484eda0ed7bb590317c3d270651f1835eb04c06cebb754abfc46e4e8496b02149bca3adbb9acff6b9f12af769f34881d1b923148
6
+ metadata.gz: d2d6917890967a3e9f982cd088a2786cb706752f6394f5d9ca7e7f9d6521d96f859662c6211a7c13c1183305c5e25bd2f833be73258d3c7970a9cdc6689cd362
7
+ data.tar.gz: b9b561f882dab6be75acb6b79233be0b42d9e6a410c58ebd43ecb47d53453db667981d39f0516e0b8a9da45965a756a7cd1317a86bf0f3abc95faaaefbb95fc1
@@ -1 +1 @@
1
- a&G�;|�qq;��$@����O8L��*��u��V&1��be��+�Ǚ�/�'���I�X��o�R%�e�?v)�}��`�BERq�;$�L,��"�����uw"XCm�J�(�ހ�T"����D��P�p���E�Dut�&�E,�[�K��B���3��=-~�h�s��E/�����?�P����D�8�Q*(Y,�,o�M�}���GI+�����R�yp� � ��N~��oۦ��s�ȕ, ~,p�T�
1
+ �!���x/����얮G����4S���CsS����]E
data.tar.gz.sig CHANGED
Binary file
@@ -2,32 +2,38 @@
2
2
 
3
3
  # file: xthreads.rb
4
4
 
5
- class XThreads
5
+ class XThreads < Hash
6
6
 
7
7
  def initialize()
8
- @threads = {}
8
+ @threads = self
9
9
  end
10
10
 
11
11
  class XThread
12
+
13
+ attr_reader :state
14
+
12
15
  def initialize(name, options={}, &blk)
13
- opts = {interval: 4}.merge(options)
16
+ opts = {interval: 4, loop: true}.merge(options)
14
17
  @name = name
15
18
  @initialized = true
16
- @start = false
19
+ @state = :stop
17
20
 
18
21
  @thread = Thread.new do
19
22
  puts "#{name} created\n"
20
- Thread.current['name'] = name;
21
- loop do
23
+ Thread.current['name'] = name
24
+ loop = true
25
+ while loop == true do
22
26
 
23
- if @start == true then
27
+ if @state == :start then
24
28
  blk.call
29
+ @state = :dead
30
+ loop = false if opts[:loop] == false
25
31
  else
26
32
  puts 'stopped' unless @initialized == true
27
33
  @initialized = false
28
34
  end
29
35
 
30
- Thread.stop if @start == false
36
+ Thread.stop if @state == :stop
31
37
 
32
38
  sleep opts[:interval]
33
39
  end
@@ -37,27 +43,45 @@ class XThreads
37
43
 
38
44
  def start
39
45
  puts "#{@name} starting ..."
40
- @start = true
46
+ @state = :start
41
47
  @thread.run
42
48
  end
43
49
 
44
50
  def stop
45
51
  puts "'#{@name}' stopping ..."
46
- @start = false
52
+ @state = :stop
47
53
  end
48
54
 
49
55
  def kill
50
56
  puts 'XThread killed'
51
57
  @thread.kill
58
+ @state = :dead
59
+ end
60
+
61
+ def thread
62
+ @thread
52
63
  end
53
64
  end
54
65
 
55
66
  def create_loop(name, options={}, &blk)
56
- @threads[name] = XThread.new name, options, &blk
67
+ @threads[name] = XThread.new name, options, &blk
57
68
  @threads[name]
58
69
  end
59
-
60
- def list()
61
- @threads
70
+
71
+ def create_thread(name, options={}, &blk)
72
+ cleanup
73
+ @threads[name] = XThread.new name, options.merge(interval: 0, loop: false), &blk
74
+ @threads[name]
62
75
  end
63
- end
76
+
77
+ private
78
+
79
+ # Remove any dead threads
80
+ #
81
+ def cleanup()
82
+ @threads.each do |name, thread|
83
+ @threads.delete name if thread.state == :dead
84
+ end
85
+ end
86
+
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xthreads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -29,7 +29,7 @@ cert_chain:
29
29
  8zMNMbb01yzfDo+1zSIq3Cu+Qiq22G7x9n8j2d09oc6xYiruzAYY8k51fyvuHxHp
30
30
  bzFPWySJi8C6r27XzfjSgV37vLLCUxsV
31
31
  -----END CERTIFICATE-----
32
- date: 2013-07-27 00:00:00.000000000 Z
32
+ date: 2013-11-01 00:00:00.000000000 Z
33
33
  dependencies: []
34
34
  description:
35
35
  email: james@r0bertson.co.uk
@@ -48,12 +48,12 @@ require_paths:
48
48
  - lib
49
49
  required_ruby_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
metadata.gz.sig CHANGED
Binary file