<commit_before><?php
/**
 * Expressif- stream implementation
 * @author <NAME>
 * @license MIT
 */
namespace Expressif\Stream {


  class Loop {

    /**
     * Gets the loop status
     */
    public static $run = false;

    /**
     * List of attached items
     */
    public static $items;

    /**
     * The event base
     */
    public static $base;

    /**
     * Creates a stream reader
     * @return Reader
     */
    public static function read($stream) {
      return new Reader($stream);
    }

    /**
     * Creates a bufferized stream
     * @return Buffer
     */
    public static function buffer($stream) {
      if (is_string($stream)) {
        $handle = stream_socket_client($stream, $errno, $errstr);
        if (!$stream) {
          throw new \Exception(
            "Could not connect to $stream ($errno:$errstr)"
          );
        }
        $stream = $handle;
      }
      return new Buffer($stream);
    }

    /**
     * Attach the specified event instance
     */
    public static function attachEvent($event, $timeout = -1) {
      if (event_base_set($event, self::$base) === false) {
        throw new \Exception('Unable to attach event to libevent');
      }
      event_add($event, $timeout);
    }

    /**
     * Attach the specified buffer
     */
    public static function attachBuffer(Buffer $buffer) {
      if (event_buffer_base_set($buffer->event, self::$base) === false) {
        throw new \Exception('Unable to attach buffer to libevent');
      }
    }

    /**
     * Calls the specified callback at each interval (ms)
     * @return Timer
     */
    public static function setInterval($fn, $interval) {
      $e = new Timer($fn, $interval);
      self::$items->attach($e);
      return $e;
    }

    /**
     * Clear the specified interval
     */
    public static function clearInterval(Timer $timer) {
      self::$items->detach($timer);
      $timer->__destruct();
    }

    /**
     * Attach the specified callback on the specified descriptor
     * @return Event
     */
    public static function stop() {
      self::$run = false;
      event_base_loopexit(self::$base, 1000);
    }

    /**
     * Check if the loop is started
     */
    public static function isStarted() {
      return self::$run;
    }

    /**
     * Starts the event loop
     */
    public static function start() {
      self::$run = true;
      while(self::$run) {
        if (event_base_loop(self::$base, EVLOOP_ONCE) === 1) {
          break; // loop is empty
        }
      }
      self::$run = false;
    }
  }

  // MAGIC ! automatically run after the script was initialized
  define('IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
  Loop::$base = event_base_new();
  Loop::$items = new \SplObjectStorage();
  register_shutdown_function(function() {
    if (!Loop::isStarted()) {
      Loop::start();
    }
  });
}<commit_msg>remove unused windows constant<commit_after><?php
/**
 * Expressif- stream implementation
 * @author <NAME>
 * @license MIT
 */
namespace Expressif\Stream {


  class Loop {

    /**
     * Gets the loop status
     */
    public static $run = false;

    /**
     * List of attached items
     */
    public static $items;

    /**
     * The event base
     */
    public static $base;

    /**
     * Creates a stream reader
     * @return Reader
     */
    public static function read($stream) {
      return new Reader($stream);
    }

    /**
     * Creates a bufferized stream
     * @return Buffer
     */
    public static function buffer($stream) {
      if (is_string($stream)) {
        $handle = stream_socket_client($stream, $errno, $errstr);
        if (!$stream) {
          throw new \Exception(
            "Could not connect to $stream ($errno:$errstr)"
          );
        }
        $stream = $handle;
      }
      return new Buffer($stream);
    }

    /**
     * Attach the specified event instance
     */
    public static function attachEvent($event, $timeout = -1) {
      if (event_base_set($event, self::$base) === false) {
        throw new \Exception('Unable to attach event to libevent');
      }
      event_add($event, $timeout);
    }

    /**
     * Attach the specified buffer
     */
    public static function attachBuffer(Buffer $buffer) {
      if (event_buffer_base_set($buffer->event, self::$base) === false) {
        throw new \Exception('Unable to attach buffer to libevent');
      }
    }

    /**
     * Calls the specified callback at each interval (ms)
     * @return Timer
     */
    public static function setInterval($fn, $interval) {
      $e = new Timer($fn, $interval);
      self::$items->attach($e);
      return $e;
    }

    /**
     * Clear the specified interval
     */
    public static function clearInterval(Timer $timer) {
      self::$items->detach($timer);
      $timer->__destruct();
    }

    /**
     * Attach the specified callback on the specified descriptor
     * @return Event
     */
    public static function stop() {
      self::$run = false;
      event_base_loopexit(self::$base, 1000);
    }

    /**
     * Check if the loop is started
     */
    public static function isStarted() {
      return self::$run;
    }

    /**
     * Starts the event loop
     */
    public static function start() {
      self::$run = true;
      while(self::$run) {
        if (event_base_loop(self::$base, EVLOOP_ONCE) === 1) {
          break; // loop is empty
        }
      }
      self::$run = false;
    }
  }

  // MAGIC ! automatically run after the script was initialized
  Loop::$base = event_base_new();
  Loop::$items = new \SplObjectStorage();
  register_shutdown_function(function() {
    if (!Loop::isStarted()) {
      Loop::start();
    }
  });
}
{'fraction_non_alphanumeric': 0.1345784604643044, 'fraction_numerical': 0.0024437074533077328, 'mean_word_length': 2.1073752711496745, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3076970', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1658, 'n_words': 458}