soar_thread_worker 0.1.1 → 0.2.0

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: 3290f53882bc33a62546eb01df317aed01a69f0e
4
- data.tar.gz: 0730cad41cb766031d3539415b239f024671158b
3
+ metadata.gz: 12278b63bb40751f6cf5aad90c30df6e6bdbc288
4
+ data.tar.gz: b821b7ff647ad3e481b8952a5648639cdc5d87ea
5
5
  SHA512:
6
- metadata.gz: a0c89c935728d4f5b091ea159dc5549dcb3570be2128dbd30d15b48c38708da8a90ad348a5a903c2464d388fd92f0a5d34781825f9b7c6b7920c3bf44ef38519
7
- data.tar.gz: 478e091a510ef1536393a74dd373e39f38997fcd653f1277df463396fd5a553db5b7efbd7f18904b2c39941120c48310eadb70247e36673fcb1148e01408bada
6
+ metadata.gz: f072de35033b8eed503613858ddddea4b2ae5166462ad80b3780723417ac873b615d4ec1b8475c0fe172e59d913cd0d7c99e43aa0d1e1b9e37ea1e8a30b28e04
7
+ data.tar.gz: ba9bfe7e14e1cad90cc2927a96144f124545836d257f45d16f3a6b34b42dfe0acdb0a729cb154ce2a03f9d69412677f8eb938b99efb7f7bf2d6bf90ac56fbfa1
@@ -11,29 +11,33 @@ module SoarThreadWorker
11
11
  $stderr.puts "ERROR [ThreadWorker] #{message}"
12
12
  end
13
13
 
14
- def initialize(event_handler)
15
- @running = false
14
+ def initialize(event_handler: nil)
15
+ @api_mutex = Mutex.new
16
16
  @stopping = false
17
17
  @event_handler = event_handler
18
18
  end
19
19
 
20
20
  def running?
21
- @running and not @thread.nil?
21
+ (not @thread.nil?) and @thread.alive?
22
22
  end
23
23
 
24
24
  def start
25
- begin
26
- return if (running?)
27
- create_thread()
28
- @running = true
29
- rescue Exception => e
30
- ThreadWorker::error("Exception #{e} in start")
31
- end
25
+ @api_mutex.synchronize {
26
+ begin
27
+ return if (running?)
28
+ @stopping = false
29
+ create_thread()
30
+ rescue Exception => e
31
+ ThreadWorker::error("Exception #{e} in start")
32
+ end
33
+ }
32
34
  end
33
35
 
34
- def stop
35
- @stopping = true
36
- @thread = nil
36
+ def stop(immediate: false)
37
+ @api_mutex.synchronize {
38
+ @stopping = true
39
+ @thread.kill if (not @thread.nil?) and immediate
40
+ }
37
41
  end
38
42
 
39
43
  def execute
@@ -50,7 +54,6 @@ module SoarThreadWorker
50
54
  stop if execute
51
55
  be_nice
52
56
  end
53
- @running = false
54
57
  end
55
58
 
56
59
  def create_thread
@@ -1,3 +1,3 @@
1
1
  module SoarThreadWorker
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_thread_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-08-19 00:00:00.000000000 Z
12
+ date: 2016-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler