examples/example_semaphore.rb in daemon_runner-0.4.1 vs examples/example_semaphore.rb in daemon_runner-0.4.2

- old
+ new

@@ -3,9 +3,29 @@ require_relative '../lib/daemon_runner' require 'dev/consul' @service = 'myservice' @lock_count = 3 -@locked = false +@lock_time = 10 -@semaphore = DaemonRunner::Semaphore.start(@service) -DaemonRunner::Semaphore.lock(@lock_count) +::Dev::Consul.run +::Dev::Consul.wait + +# Get a new semaphore +@semaphore = DaemonRunner::Semaphore.lock(@service, @lock_count) + +# Spawn a thread to handle renewing the lock +@renew_thread = @semaphore.renew + +# Do whatever kind of work you want +@lock_time.downto(0).each do |i| + puts "Releasing lock in #{i} seconds" + sleep 1 +end + +# Kill the thread when you're done +@renew_thread.kill + +# Explicitly release the semaphore when you're done +@semaphore.release + +::Dev::Consul.stop