Last active
October 21, 2018 08:25
-
-
Save csmr/177daf69dfaffed11306f9a5b6fa0cbf to your computer and use it in GitHub Desktop.
nil hel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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