WhisperKit icon indicating copy to clipboard operation
WhisperKit copied to clipboard

Mark public callbacks Sendable

Open naykutguven opened this issue 5 months ago • 0 comments

This pull request refactors the callback type signatures throughout the WhisperKit codebase to improve thread safety and clarity. The main change is the consistent use of the @Sendable attribute for callback typealiases (such as TranscriptionCallback, SegmentDiscoveryCallback, and others), ensuring they are safe to use in concurrent contexts. Additionally, the code updates function and method signatures to expect optional TranscriptionCallback? parameters instead of non-optional defaults, and updates all usages accordingly.

Concurrency and Callback Improvements

  • Added @Sendable to all major callback typealiases, including TranscriptionCallback, AudioStreamTranscriberCallback, SegmentDiscoveryCallback, ModelStateCallback, and TranscriptionStateCallback, making them safe for use in concurrent Swift contexts.
  • Updated TranscriptionCallback to be non-optional in its typealias, and changed method and function signatures across the codebase to accept TranscriptionCallback? (i.e., optional) parameters, improving clarity and flexibility.

Code Consistency and Usage Updates

  • Replaced all inline callback type definitions (e.g., (TranscriptionProgress) -> Bool?) with the new TranscriptionCallback typealias in function parameters and local variables, ensuring consistency across the codebase.

These changes help make the codebase safer for concurrency, easier to maintain, and more consistent.

naykutguven avatar Nov 24 '25 10:11 naykutguven