xthreads 0.1.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.
Files changed (2) hide show
  1. data/lib/xthreads.rb +63 -0
  2. metadata +56 -0
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: xthreads.rb
4
+
5
+ class XThreads
6
+
7
+ def initialize()
8
+ @threads = {}
9
+ end
10
+
11
+ class XThread
12
+ def initialize(name, options={}, &blk)
13
+ opts = {interval: 4}.merge(options)
14
+ @name = name
15
+ @initialized = true
16
+ @start = false
17
+
18
+ @thread = Thread.new do
19
+ puts "#{name} created\n"
20
+ Thread.current['name'] = name;
21
+ loop do
22
+
23
+ if @start == true then
24
+ blk.call
25
+ else
26
+ puts 'stopped' unless @initialized == true
27
+ @initialized = false
28
+ end
29
+
30
+ Thread.stop if @start == false
31
+
32
+ sleep opts[:interval]
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ def start
39
+ puts "#{@name} starting ..."
40
+ @start = true
41
+ @thread.run
42
+ end
43
+
44
+ def stop
45
+ puts "'#{@name}' stopping ..."
46
+ @start = false
47
+ end
48
+
49
+ def kill
50
+ puts 'XThread killed'
51
+ @thread.kill
52
+ end
53
+ end
54
+
55
+ def create_loop(name, options={}, &blk)
56
+ @threads[name] = XThread.new name, options, &blk
57
+ @threads[name]
58
+ end
59
+
60
+ def list()
61
+ @threads
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xthreads
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors: []
8
+
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-03 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email:
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/xthreads.rb
27
+ has_rdoc: true
28
+ homepage:
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.5.2
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: xthreads
55
+ test_files: []
56
+