Skip to content

Commit

Permalink
Run multiple machines.
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Aug 9, 2019
1 parent 2640bc0 commit a916e61
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/backport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class << self
# @param adapter [Adapter]
# @return [void]
def prepare_stdio_server adapter: Adapter
machine.prepare Backport::Server::Stdio.new(adapter: adapter)
machines.last.prepare Backport::Server::Stdio.new(adapter: adapter)
end

# Prepare a TCP server to run in Backport.
Expand All @@ -25,15 +25,15 @@ def prepare_stdio_server adapter: Adapter
# @param adapter [Adapter]
# @return [void]
def prepare_tcp_server host: 'localhost', port: 1117, adapter: Adapter
machine.prepare Backport::Server::Tcpip.new(host: host, port: port, adapter: adapter)
machines.last.prepare Backport::Server::Tcpip.new(host: host, port: port, adapter: adapter)
end

# Prepare an interval server to run in Backport.
#
# @param period [Float] Seconds between intervals
# @return [void]
def prepare_interval period, &block
machine.prepare Backport::Server::Interval.new(period, &block)
machines.last.prepare Backport::Server::Interval.new(period, &block)
end

# Run the Backport machine. The provided block will be executed before the
Expand All @@ -48,14 +48,18 @@ def prepare_interval period, &block
#
# @return [void]
def run &block
machine = Machine.new
machines.push machine
machine.run &block
machines.delete machine
end

# Stop the Backport machine.
# Stop all running Backport machines.
#
# @deprecated This might not be a good idea.
# @return [void]
def stop
machine.stop
machines.last.stop
end

def logger
Expand All @@ -64,9 +68,9 @@ def logger

private

# @return [Machine]
def machine
@machine ||= Machine.new
# @return [Array<Machine>]
def machines
@machines ||= []
end
end
end

0 comments on commit a916e61

Please sign in to comment.