Sha256: eb35be4e95f3f9ce778adbeb755ba714729e2c9a2f48ffe4c0a5bac2e5753b11
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# Copyright (c) 2018 Yegor Bugayenko # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require_relative 'log' require_relative 'verbose_thread' # Background routines. # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko # License:: MIT module Zold # NODE command class Routines def initialize(log = Log::Quiet.new) @log = log @threads = [] end def add(seconds = 60) @threads << Thread.start do VerboseThread.new(@log).run(true) do Thread.current.name = 'routines' count = 0 loop do sleep(seconds) yield count count += 1 end end end end def stop @threads.each do |t| t.exit @log.debug("#{t.name} thread stopped") end @log.info("#{@threads.count} routine threads stopped") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zold-0.11.18 | lib/zold/routines.rb |
zold-0.11.17 | lib/zold/routines.rb |