Skip to content

Instantly share code, notes, and snippets.

@csmr
Last active October 21, 2018 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csmr/177daf69dfaffed11306f9a5b6fa0cbf to your computer and use it in GitHub Desktop.
Save csmr/177daf69dfaffed11306f9a5b6fa0cbf to your computer and use it in GitHub Desktop.
nil hel
# Reads from a named pipe
# @agument timeout_secs_int - timeout for waiting on something to read
# @return nil if nothing to read
def read_line_nonblocking( pipe_handle_io, timeout_secs_int=0 )
rwe = IO.select([pipe_handle_io], [], [], timeout_secs_int)
msg = rwe[0][0].gets unless rwe==nil || rwe[0][0]==nil
msg.strip if msg!=nil
end
# read_pipes
def read_pipes
msg = read_line_nonblocking(@pipe_from_stateserver, @refreshdelay_secs)
msg == nil ? return : msg = msg.split(" ")
update_model( msg[1] ) if msg[0] == "STATE"
end
def resolve_state
msg = @msg_stack.shift.split(' ')
case msg[0]
when "GET"
@pipe_to_ui.puts get_state( msg[1] )
@pipe_to_ui.flush
when "SET"
set_state( msg[1] )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment