<commit_before>class Radiodan
class Panic
  include Logging
  
  def initialize(config)
    @panic      = false
    @timeout    = config.delete(:duration).to_i
    @playlist   = config[:playlist]
  end
  
  def call(player)
    @player = player
    
    @player.register_event :panic do
      panic!
    end
  end
  
  def panic?
    @panic == true
  end

  def panic!
    return true if panic?
    
    @panic = true
    
    original_state = @player.playlist
  
    Thread.new do
      logger.debug "panic for #{@timeout} seconds"
      @player.playlist = @playlist
      sleep(@timeout)
      return_to_state original_state
    end
  
    @panic<commit_msg>Use EM:defer instead of Thread.new in panic mode<commit_after>class Radiodan
class Panic
  include Logging
  
  def initialize(config)
    @panic      = false
    @timeout    = config.delete(:duration).to_i
    @playlist   = config[:playlist]
  end
  
  def call(player)
    @player = player
    
    @player.register_event :panic do
      panic!
    end
  end
  
  def panic?
    @panic == true
  end

  def panic!
    return true if panic?
    
    @panic = true
    
    original_state = @player.playlist
  
    EM.defer \
      proc {
        logger.debug "panic for #{@timeout} seconds"
        @player.playlist = @playlist
        sleep(@timeout)
      }, 
      proc {
        return_to_state original_state
      }
  
    @panic
{'fraction_non_alphanumeric': 0.0830945558739255, 'fraction_numerical': 0.0, 'mean_word_length': 2.050218340611354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3200569', 'n_tokens_mistral': 450, 'n_tokens_neox': 446, 'n_words': 114}