lib/jekyll-postcss/socket.rb in jekyll-postcss-0.4.0 vs lib/jekyll-postcss/socket.rb in jekyll-postcss-0.4.1

- old
+ new

@@ -47,21 +47,29 @@ @env ||= Jekyll.env @env == "development" end + MAX_ATTEMPTS = 100 + def start_dev_server Thread.new do system "#{START_SCRIPT} #{POSTCSS_SCRIPT} --development" end - @postcss = nil - while @postcss.nil? + attempts = 0 + @postcss = begin - @postcss = TCPSocket.open("localhost", 8124) - rescue StandardError - nil # Suppressing exceptions + TCPSocket.open("localhost", 8124) + rescue StandardError => e + attempts = attempts + 1 + + if attempts < MAX_ATTEMPTS + sleep 0.1 + retry + else + raise "Could not connect to the PostCSS server" + end end - end end end end