WhisperKit
WhisperKit copied to clipboard
Mark public callbacks Sendable
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
@Sendableto all major callback typealiases, includingTranscriptionCallback,AudioStreamTranscriberCallback,SegmentDiscoveryCallback,ModelStateCallback, andTranscriptionStateCallback, making them safe for use in concurrent Swift contexts. - Updated
TranscriptionCallbackto be non-optional in its typealias, and changed method and function signatures across the codebase to acceptTranscriptionCallback?(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 newTranscriptionCallbacktypealias 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.