Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created March 20, 2020 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/2ee0e51816ac2d18c2bcb5ba7f4ca055 to your computer and use it in GitHub Desktop.
Save havenwood/2ee0e51816ac2d18c2bcb5ba7f4ca055 to your computer and use it in GitHub Desktop.
Example for xco on #ruby IRC
class Xco
attr_accessor :reaper
def initialize
@reaper = Automaton.new self
@reaper.start
end
class Automaton
def initialize(source, function: :reap, interval: 1)
@source = source
@interval = interval
@function = function
@running = false
end
def start
@running = true
case @function
when :reap
@thread = Thread.new do
while @running
sleep @interval
# Find files that are too old and delete them.
puts "Tick, tock ..."
end
end
end
end
def stop
@running = false
@thread.wakeup
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment