lifeguard 0.0.9 → 0.1.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: 8c0e136e3ea9cf546ef269e33ebd6b5e1f84fa7f
4
- data.tar.gz: af7f496ae700677de545303d763bca5eb285d648
3
+ metadata.gz: 38a6ae4b7f5e2893ad8b4d96a2c2abd5670c8d4e
4
+ data.tar.gz: c9e0e58a5f1d7e5c6874c1658440060a39c6cc9d
5
5
  SHA512:
6
- metadata.gz: b0d4d7ef4c2f6fa8a18e8dba4ce01ea25f1ae72c838c30833e6316120ee8582fdacafde991d87f02e96dfac7708ae8f68858fe6684572bda33704993702bdfb6
7
- data.tar.gz: 333d49ff95dd267e49e0e38a3f151729c21b2fee459f5bbb6616c2b6aa8abe24428c870c5bcb9ce871efc5191ed8dbae79358a2347fbb42fe338b9afef430b10
6
+ metadata.gz: 1caef71d23d17bc09ee6321f528b5985b4596719a79fac0af58bb3042f0ac99ba46e35baf5f40c9071336940ae6c4b123bd25c07746bd42296e328e40f195cff
7
+ data.tar.gz: d6aa30010eba324f2bbe6992f9722bd412953cdf90a3a136889f9a040de8b24a4b8fddeada863301ac7142a06442b07e38df8a3c3bc7b7760573e560f2597ab7
@@ -8,28 +8,32 @@ module Lifeguard
8
8
  super(opts)
9
9
  @queued_jobs = ::Queue.new
10
10
  @shutdown = false
11
+ @super_async_mutex = ::Mutex.new
11
12
  end
12
13
 
14
+ # Handle to original async method
15
+ # for check_queued_jobs to use directly
16
+ alias_method :super_async, :async
17
+
13
18
  def async(*args, &block)
14
19
  return false if @shutdown
15
-
20
+ @queued_jobs << { :args => args, :block => block }
16
21
  check_queued_jobs
17
- job_started = super
18
-
19
- unless job_started
20
- @queued_jobs << { :args => args, :block => block }
21
- end
22
22
 
23
- job_started
23
+ return true
24
24
  end
25
25
 
26
26
  def check_queued_jobs
27
- return if busy?
28
- return if @queued_jobs.size <= 0
29
-
30
- queued_job = @queued_jobs.pop
31
- async(*queued_job[:args], &queued_job[:block])
32
- check_queued_jobs
27
+ loop do
28
+ break if busy?
29
+ break if @queued_jobs.size <= 0
30
+
31
+ @super_async_mutex.synchronize do
32
+ break if busy?
33
+ queued_job = @queued_jobs.pop
34
+ super_async(*queued_job[:args], &queued_job[:block])
35
+ end
36
+ end
33
37
  end
34
38
 
35
39
  def kill!(*args)
@@ -1,3 +1,3 @@
1
1
  module Lifeguard
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifeguard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stien
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-21 00:00:00.000000000 Z
12
+ date: 2016-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: better_receive
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.2.2
157
+ rubygems_version: 2.5.1
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: A Supervised threadpool implementation in ruby.