dream-ops 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 635291c5f60c092e9a6aadccbbb94b9c406f44aa
4
- data.tar.gz: b53af42711e3c850419e528221e568bf14c136b7
3
+ metadata.gz: 27d08df0920a99854a22195056728c0532fc10fa
4
+ data.tar.gz: 7f00fa02c6681181ce6bff20e4e49ce8cbb58312
5
5
  SHA512:
6
- metadata.gz: dec24a3be06450e6b4aadd9907d65e5f3020681680337bf8c8e119e76ce1e39049fdfb22dc712195135d0a60b992aa365ad1652a9e99e1268efc44e1a681e1ad
7
- data.tar.gz: 52451f10fd6658f6b443ad632c60285c24be4b28d3117fafa45bc617638e40eeaa8e603d3543b4a9a53c737c8a95ff9ff65d6607983f4b50aa5d3e8abdb4c69f
6
+ metadata.gz: 29d9d09a2e49a281b95f4331a92f3f0edd2348945f8c0ee80ba2042c4bf145add1e57291a71a6df5dbf6c5ef7dcdfad99c6d6ca227fdd4df1de0cfbb5060891d
7
+ data.tar.gz: 68b9ff0471cb4327abef80661686d3dd5cc011f216d613db66653c1ccf4eebadbeef94b32bf3301965e13dcd3a50889ea10f18df370a08620bbe49d282518ff8
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.6.1]
10
+
11
+ ### Fixes
12
+ - Now using thread-safe enum to avoid `FiberError`
13
+
9
14
  ## [0.6.0]
10
15
 
11
16
  ### Added
@@ -1,14 +1,16 @@
1
- require "dream-ops/utils/zip"
1
+ require 'dream-ops/utils/zip'
2
+ require 'dream-ops/utils/threaded_enum'
2
3
  require 'fileutils'
3
4
 
4
5
  module DreamOps
5
6
  class BaseDeployer
6
- @@spinner = Enumerator.new do |e|
7
+
8
+ @@spinner = ThreadedEnum.new do |e|
7
9
  loop do
8
- e.yield '|'
9
- e.yield '/'
10
- e.yield '-'
11
- e.yield '\\'
10
+ e << '|'
11
+ e << '/'
12
+ e << '-'
13
+ e << '\\'
12
14
  end
13
15
  end
14
16
 
@@ -0,0 +1,81 @@
1
+ # Credit: https://github.com/bittrance/rxruby/blob/master/lib/rx/concurrency/threaded_enumerator.rb
2
+ #
3
+ # ThreadedEnum can be used across threads unlike Ruby's default Enumerator
4
+ # that will throw FiberError if the enumerator is used from more than one
5
+ # thread.
6
+ class ThreadedEnum
7
+ ERROR = Object.new
8
+ DONE = Object.new
9
+
10
+ if RUBY_ENGINE == 'jruby'
11
+ def self.new(*args, &block)
12
+ Enumerator.new(*args, &block)
13
+ end
14
+ end
15
+
16
+ # ThreadedEnum helper class
17
+ class Yielder
18
+ def initialize(queue, gate, condition)
19
+ @queue = queue
20
+ @gate = gate
21
+ @condition = condition
22
+ end
23
+
24
+ def <<(e)
25
+ @queue << e
26
+ @gate.synchronize do
27
+ @condition.wait @gate while @queue.size > 0
28
+ end
29
+ end
30
+ end
31
+
32
+ # The enumerator can be created with either an enumerable or a block that
33
+ # receives a yielder object, but not both. Note that the block or enumerable
34
+ # will be iterated immediately once making it possible to prepare the iterator
35
+ # e.g. when reading from a file or a socket.
36
+ def initialize(source_or_size_hint = nil, &block)
37
+ raise TypeError, 'Size hinting not supported' if source_or_size_hint && block_given?
38
+ @condition = ConditionVariable.new
39
+ @gate = Mutex.new
40
+ @queue = Queue.new
41
+ @done = false
42
+ setup_yielder(source_or_size_hint, &block)
43
+ end
44
+
45
+ # Receive the next item from the enumerator or any exception thrown from the
46
+ # enumerator.
47
+ def next
48
+ raise StopIteration if @done
49
+ @gate.synchronize do
50
+ @condition.signal
51
+ end
52
+ payload, type = @queue.pop
53
+ case type
54
+ when DONE
55
+ @done = true
56
+ raise StopIteration
57
+ when ERROR
58
+ @done = true
59
+ raise payload
60
+ end
61
+ payload
62
+ end
63
+
64
+ private
65
+
66
+ def setup_yielder(source, &block)
67
+ yielder = Yielder.new(@queue, @gate, @condition)
68
+ Thread.new do
69
+ begin
70
+ if source
71
+ source.each { |e| yielder << e }
72
+ else
73
+ block.call yielder
74
+ end
75
+ rescue => e
76
+ yielder << [e, ERROR]
77
+ end
78
+ yielder << [nil, DONE]
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module DreamOps
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dream-ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Allen
@@ -157,6 +157,7 @@ files:
157
157
  - lib/dream-ops/logger.rb
158
158
  - lib/dream-ops/mixin/logging.rb
159
159
  - lib/dream-ops/shell.rb
160
+ - lib/dream-ops/utils/threaded_enum.rb
160
161
  - lib/dream-ops/utils/zip.rb
161
162
  - lib/dream-ops/version.rb
162
163
  homepage: https://github.com/chris-allen/dream-ops