pi_piper icon indicating copy to clipboard operation
pi_piper copied to clipboard

Event every x number of time?

Open ghost opened this issue 10 years ago • 2 comments

Would it be possible to add a feature so we can enter an event loop and beforehand setup functions that would run every x milliseconds? This way we can concurrently check for different sensors. I know I could do this with event machine but it seems that would defeat the purpose of this library if its supposed to be event driven.

ghost avatar Apr 05 '14 01:04 ghost

You don't need event machine to do this, ruby threads work just fine.

checker_thread = Thread.new do
  loop do
      check_your_sensors
      sleep 1       # or however many seconds you want to sleep
   end
end

Now that you have a reference to that thread, you can join or kill it as you please.

bguest avatar Apr 06 '14 03:04 bguest

I like the idea! It's something I've thought about before.

Unfortunately, work and personal life have me swamped lately. So I doubt I'll be able to get to this in short order. Though, I'd never say "no" to a pull request :smile:

jwhitehorn avatar Apr 06 '14 12:04 jwhitehorn