Sha256: ff44d4aa7aa2d3719b337859d88cfa4aed734de3793c16ae63fe01969d0aee6a

Contents?: true

Size: 463 Bytes

Versions: 5

Compression:

Stored size: 463 Bytes

Contents

module Mumble
  module ThreadTools
    class DuplicateThread < StandardError; end

    protected
    def spawn_thread(sym)
      raise DuplicateThread if threads.has_key? sym
      threads[sym] = Thread.new { loop { send sym } }
    end

    def spawn_threads(*symbols)
      symbols.map { |sym| spawn_thread sym }
    end

    def kill_threads
      threads.values.map(&:kill)
      threads.clear
    end

    def threads
      @threads ||= {}
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mumble-ruby2-1.1.4 lib/mumble-ruby2/thread_tools.rb
mumble-ruby-1.1.3 lib/mumble-ruby/thread_tools.rb
mumble-ruby-1.1.2 lib/mumble-ruby/thread_tools.rb
mumble-ruby-1.1.1 lib/mumble-ruby/thread_tools.rb
mumble-ruby-1.1.0 lib/mumble-ruby/thread_tools.rb