// Handle — internal state of a running clipboard watcher.
//
// The watcher task spawned in `Clipboard::watch` polls `running` to know
// whether to keep looping and waits on `wakeup` so `stop()` can break
// the poll sleep without waiting for the next interval.

///|
pub struct Handle {
  priv mut running : Bool
  priv wakeup : @cond_var.Cond
}

///|
fn Handle::new() -> Handle {
  { running: true, wakeup: @cond_var.Cond::Cond() }
}

///|
pub fn Handle::stop(self : Handle) -> Unit {
  // Idempotent: the watcher exits as soon as it observes `running=false`,
  // so a second `stop()` is a no-op.
  if self.running {
    self.running = false
    self.wakeup.broadcast()
  }
}