Sha256: 56633a1875ba93829f72104d64f3382f1bee4ebef8f15a651c99dd5c80b01fbe
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
module Backport class Machine def initialize @stopped = true end # Run the machine. If a block is provided, it gets executed before the # maching starts its main loop. The main loop halts program execution # until the machine is stopped. # # @return [void] def run return unless stopped? servers.clear @stopped = false yield if block_given? run_server_thread end # Stop the machine. # # @return [void] def stop servers.map(&:stop) servers.clear @stopped = true end # True if the machine is stopped. # def stopped? @stopped ||= false end # Add a server to the machine. The server will be started when the machine # starts. If the machine is already running, the server will be started # immediately. # # @param server [Server::Base] # @return [void] def prepare server servers.push server server.start unless stopped? end private # @return [Array<Server::Base>] def servers @servers ||= [] end def run_server_thread servers.map(&:start) until stopped? servers.each(&:tick) sleep 0.001 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
backport-0.2.0 | lib/backport/machine.rb |