<commit_before>package com.lynbrookrobotics.potassium.streams

import scala.collection.mutable

class SlidingStream[T](parent: Stream[T], size: Int) extends Stream[Seq[T]] {
  override private[potassium] val parents = Seq(parent)
  override private[potassium] val streamType = "sliding"

  private var unsubscribe: Cancel = null
  private val currentData = mutable.Queue.empty[T]
  private var valuesLeft = size // start from 1

  override def tryFix(): Unit = {
    currentData.clear()
    valuesLeft = size
  }

  override def subscribeToParents(): Unit = {
    unsubscribe = parent.foreach { v =>
      currentData.enqueue(v)

      if (valuesLeft > 0) {
        valuesLeft -= 1
      }<commit_msg>Improve fix for broken sliding link to completely reset the queue (#203)<commit_after>package com.lynbrookrobotics.potassium.streams

import scala.collection.mutable

class SlidingStream[T](parent: Stream[T], size: Int) extends Stream[Seq[T]] {
  override private[potassium] val parents = Seq(parent)
  override private[potassium] val streamType = "sliding"

  private var unsubscribe: Cancel = null
  private var currentData = mutable.Queue.empty[T]
  private var valuesLeft = size // start from 1

  override def tryFix(): Unit = {
    currentData = mutable.Queue.empty[T]
    valuesLeft = size
    val origUnsubscribe = unsubscribe
    subscribeToParents()
    origUnsubscribe.cancel()
  }

  override def subscribeToParents(): Unit = {
    unsubscribe = parent.foreach { v =>
      currentData.enqueue(v)

      if (valuesLeft > 0) {
        valuesLeft -= 1
      }
{'fraction_non_alphanumeric': 0.09872611464968153, 'fraction_numerical': 0.005732484076433121, 'mean_word_length': 3.7319277108433737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '21335', 'n_tokens_mistral': 489, 'n_tokens_neox': 465, 'n_words': 131}