Class: AmstradGpt::Amstrad
- Inherits:
-
Object
- Object
- AmstradGpt::Amstrad
- Defined in:
- lib/amstrad_gpt/amstrad.rb
Instance Method Summary collapse
-
#initialize(tty:, base_sleep_duration: 0.1) ⇒ Amstrad
constructor
A new instance of Amstrad.
- #receive_messages ⇒ Object
- #reply(message) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(tty:, base_sleep_duration: 0.1) ⇒ Amstrad
Returns a new instance of Amstrad.
5 6 7 8 9 |
# File 'lib/amstrad_gpt/amstrad.rb', line 5 def initialize(tty:, base_sleep_duration: 0.1) @tty = tty @base_sleep_duration = base_sleep_duration setup_mutable_state end |
Instance Method Details
#receive_messages ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/amstrad_gpt/amstrad.rb', line 28 def Thread.new do loop do break unless @running = if yield if .length.positive? end sleep(base_sleep_duration * rand) end end end |
#reply(message) ⇒ Object
22 23 24 25 26 |
# File 'lib/amstrad_gpt/amstrad.rb', line 22 def reply() mutex.synchronize do interface.write() end end |
#start ⇒ Object
11 12 13 |
# File 'lib/amstrad_gpt/amstrad.rb', line 11 def start @reader_thread = Thread.new { read_bytes_loop } end |
#stop ⇒ Object
15 16 17 18 19 20 |
# File 'lib/amstrad_gpt/amstrad.rb', line 15 def stop @running = false @reader_thread.join @reader_thread = nil interface.shutdown end |