Created
March 20, 2020 19:57
-
-
Save havenwood/2ee0e51816ac2d18c2bcb5ba7f4ca055 to your computer and use it in GitHub Desktop.
Example for xco on #ruby IRC
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
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