@@ -254,18 +254,32 @@ public struct FirstResponderStateChangeHandler: Sendable {
254
254
/// cycle completes using this method. You can pass in any suitable scheduler, such as `RunLoop.main` or
255
255
/// `DispatchQueue.main`.
256
256
///
257
- public func receive< S: Scheduler > ( on scheduler: S , options: S . SchedulerOptions ? = nil ) -> Self
258
- where S : Sendable , S . SchedulerOptions : Sendable {
257
+ public func receive< S: Scheduler > ( on scheduler: S , options: S . SchedulerOptions ? = nil ) -> Self {
258
+ let _scheduler = _Scheduler ( scheduler : scheduler , options : options )
259
259
return . init(
260
260
handleStateChange: { isFirstResponder in
261
- scheduler . schedule ( options : options ) {
261
+ _scheduler . schedule {
262
262
self . handleStateChange ( isFirstResponder)
263
263
}
264
264
} ,
265
265
canBecomeFirstResponder: canBecomeFirstResponder,
266
266
canResignFirstResponder: canResignFirstResponder
267
267
)
268
268
}
269
+
270
+ // Currently whilst DispatchQueue is unchecked sendable, RunLoop is not, and neither are
271
+ // their scheduler options so we need to wrap it in a small unchecked sendable value to
272
+ // cross the sendable boundary.
273
+ private struct _Scheduler < S: Scheduler > : @unchecked Sendable {
274
+ let scheduler : S
275
+ let options : S . SchedulerOptions ?
276
+
277
+ func schedule( _ action: @escaping @Sendable @MainActor ( ) -> Void ) {
278
+ scheduler. schedule ( options: options) {
279
+ Task { @MainActor in action ( ) }
280
+ }
281
+ }
282
+ }
269
283
}
270
284
271
285
extension FirstResponderStateChangeHandler {
0 commit comments