Skip to content

Commit f4f3d4d

Browse files
authored
Use unspecified QoS in QueueScheduler when QoS is unspecified (#880)
1 parent 196bf28 commit f4f3d4d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# master
22
*Please add new entries at the top.*
33

4+
1. Change `QueueScheduler` to use unspecified QoS when QoS parameter is defaulted
45
1. Add support for VisionOS (#875, kudos to @NachoSoto)
56
1. Fix minimum deployment target of iOS 11 in CocoaPods
67
1. Fix CI release git tag push trigger (#869, kudos to @p4checo)

Sources/Scheduler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public final class QueueScheduler: DateScheduler {
363363
/// - targeting: (Optional) The queue on which this scheduler's work is
364364
/// targeted
365365
public convenience init(
366-
qos: DispatchQoS = .default,
366+
qos: DispatchQoS = .unspecified,
367367
name: String = "org.reactivecocoa.ReactiveSwift.QueueScheduler",
368368
targeting targetQueue: DispatchQueue? = nil
369369
) {

Tests/ReactiveSwiftTests/SchedulerSpec.swift

+42
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// Copyright (c) 2014 GitHub. All rights reserved.
77
//
88

9+
#if canImport(Darwin)
10+
import Darwin.sys.qos
11+
#endif
912
import Dispatch
1013
import Foundation
1114

@@ -261,6 +264,45 @@ class SchedulerSpec: QuickSpec {
261264
// enough time to ensure that the first timer was actually cancelled.
262265
expect(count).toEventually(equal(timesToRun))
263266
}
267+
268+
it("should propagate QoS values by default") {
269+
expect(scheduler.queue.qos).to(equal(.unspecified))
270+
271+
// qos_class_self() may not be available on non-Darwin
272+
// platforms, and it's unclear if QoS propagation is
273+
// implemented in an equivalent manner in such contexts,
274+
// so we restrict runtime validation tests to Darwin.
275+
#if canImport(Darwin)
276+
let userInitiatedQueue = DispatchQueue(
277+
label: "reactiveswift.tests.user-initiated",
278+
qos: .userInitiated
279+
)
280+
userInitiatedQueue.suspend()
281+
282+
var initialQoS: qos_class_t?
283+
var endQoS: qos_class_t?
284+
285+
userInitiatedQueue.async {
286+
initialQoS = qos_class_self()
287+
288+
// scheduling should propagate QoS values by default
289+
scheduler.schedule {
290+
endQoS = qos_class_self()
291+
}
292+
}
293+
294+
scheduler.queue.resume()
295+
userInitiatedQueue.resume()
296+
297+
expect(initialQoS).toEventuallyNot(beNil())
298+
expect(endQoS).toEventuallyNot(beNil())
299+
300+
expect(initialQoS).to(equal(QOS_CLASS_USER_INITIATED))
301+
expect(endQoS?.rawValue).to(beGreaterThanOrEqualTo(
302+
initialQoS?.rawValue
303+
))
304+
#endif // canImport(Darwin)
305+
}
264306
}
265307
}
266308

0 commit comments

Comments
 (0)