hawkins 2.0.3 → 2.0.4

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: a1bd11a41ba71a67896b81cb43ee0c52027290a5
4
- data.tar.gz: b51ee35d4b5fa17c4c28591370d2e1abb064276b
3
+ metadata.gz: f929af2fc50c880c9eddc8e616f2021356374156
4
+ data.tar.gz: eab14413e1a78b4153a341f66f68c0d653ab607f
5
5
  SHA512:
6
- metadata.gz: 627dd5cc3dfdc7a2cbd9be3ec967c050bc29f43419e13605a9b74988842ab3cd2ee6f2293b9d4fc79982c92084a907ea732d12c400a5ea08e8262c9c37f437b0
7
- data.tar.gz: 8e48083f7781a9155b95685b9a85d8cf725e666c3f313147242d96b230e41fe819664a3d0b60893033ebbc10c42452427c76473de5a40fff37c53fdba0084a1a
6
+ metadata.gz: 9686c48fe8d922021257cec7f623c579f52b21f61de2988855549b94ee78502c86e6bffd3bc2c43a517cb271ea1d7899d55c65242325beb28c40f8279b76946b
7
+ data.tar.gz: 0bf0b78f452ef86dc79c0b23fdbe8d77eb123d8920c0e83be414adc25a4de137cfdb02123560e52ef80b5ca89b937d537638336e7a8a6148c14fce5de31315d9
@@ -3,6 +3,13 @@ require 'thread'
3
3
  module Hawkins
4
4
  module Commands
5
5
  class LiveServe < Jekyll::Command
6
+
7
+ # Based on pattern described in
8
+ # https://emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/
9
+ @mutex = Mutex.new
10
+ @running_cond = ConditionVariable.new
11
+ @is_running = false
12
+
6
13
  class << self
7
14
  COMMAND_OPTIONS = {
8
15
  "swf" => ["--swf", "Use Flash for WebSockets support"],
@@ -14,6 +21,8 @@ module Hawkins
14
21
 
15
22
  LIVERELOAD_PORT = 35729
16
23
 
24
+ attr_reader :mutex, :running_cond, :is_running
25
+
17
26
  #
18
27
 
19
28
  def init_with_program(prog)
@@ -51,7 +60,6 @@ module Hawkins
51
60
  destination = opts["destination"]
52
61
  setup(destination)
53
62
 
54
- @running = Queue.new
55
63
  @reload_reactor.start(opts)
56
64
 
57
65
  @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
@@ -65,12 +73,8 @@ module Hawkins
65
73
  boot_or_detach(@server, opts)
66
74
  end
67
75
 
68
- def running?
69
- !(@running.nil? || @running.empty?)
70
- end
71
-
72
76
  def shutdown
73
- @server.shutdown if running?
77
+ @server.shutdown if @is_running
74
78
  end
75
79
 
76
80
  private
@@ -185,9 +189,9 @@ module Hawkins
185
189
  private
186
190
  def launch_browser(server, opts)
187
191
  command =
188
- if Utils::Platforms.windows?
192
+ if Jekyll::Utils::Platforms.windows?
189
193
  "start"
190
- elsif Utils::Platforms.osx?
194
+ elsif Jekyll::Utils::Platforms.osx?
191
195
  "open"
192
196
  else
193
197
  "xdg-open"
@@ -255,8 +259,11 @@ module Hawkins
255
259
  def start_callback(detached)
256
260
  unless detached
257
261
  proc do
258
- @running << '.'
259
- Jekyll.logger.info("Server running...", "press ctrl-c to stop.")
262
+ mutex.synchronize do
263
+ @is_running = true
264
+ Jekyll.logger.info("Server running...", "press ctrl-c to stop.")
265
+ running_cond.signal
266
+ end
260
267
  end
261
268
  end
262
269
  end
@@ -265,8 +272,11 @@ module Hawkins
265
272
  def stop_callback(detached)
266
273
  unless detached
267
274
  proc do
268
- @reload_reactor.stop
269
- @running.clear
275
+ mutex.synchronize do
276
+ @reload_reactor.stop unless @reload_reactor.nil?
277
+ @is_running = false
278
+ running_cond.signal
279
+ end
270
280
  end
271
281
  end
272
282
  end
@@ -1,3 +1,3 @@
1
1
  module Hawkins
2
- VERSION = "2.0.3".freeze
2
+ VERSION = "2.0.4".freeze
3
3
  end
@@ -57,8 +57,10 @@ module Hawkins
57
57
  Commands::LiveServe.shutdown
58
58
  end
59
59
 
60
- while Commands::LiveServe.running?
61
- sleep(0.1)
60
+ Commands::LiveServe.mutex.synchronize do
61
+ if Commands::LiveServe.is_running
62
+ Commands::LiveServe.running_cond.wait(Commands::LiveServe.mutex)
63
+ end
62
64
  end
63
65
 
64
66
  FileUtils.remove_entry_secure(temp_dir, true)
@@ -69,8 +71,10 @@ module Hawkins
69
71
  Commands::LiveServe.start(opts)
70
72
  end
71
73
 
72
- while !Commands::LiveServe.running?
73
- sleep(0.1)
74
+ Commands::LiveServe.mutex.synchronize do
75
+ unless Commands::LiveServe.is_running
76
+ Commands::LiveServe.running_cond.wait(Commands::LiveServe.mutex)
77
+ end
74
78
  end
75
79
  end
76
80
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hawkins
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Wood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll