Skip to content

Commit e2bc6f2

Browse files
author
Karl Weinmeister
committed
Merge branch 'master' of https://github.com/kweinmeister/swift-corelibs-foundation into energyformatter
2 parents 43f4e92 + bc65598 commit e2bc6f2

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

Foundation/NSNotificationQueue.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import CoreFoundation
1212
extension NotificationQueue {
1313

1414
public enum PostingStyle : UInt {
15-
16-
case postWhenIdle
17-
case postASAP
18-
case postNow
15+
case whenIdle = 1
16+
case asap = 2
17+
case now = 3
1918
}
2019

2120
public struct NotificationCoalescing : OptionSet {
@@ -38,12 +37,12 @@ open class NotificationQueue: NSObject {
3837
internal var idleList = NSNotificationList()
3938
internal lazy var idleRunloopObserver: CFRunLoopObserver = {
4039
return CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, CFOptionFlags(kCFRunLoopBeforeTimers), true, 0) {[weak self] observer, activity in
41-
self!.notifyQueues(.postWhenIdle)
40+
self!.notifyQueues(.whenIdle)
4241
}
4342
}()
4443
internal lazy var asapRunloopObserver: CFRunLoopObserver = {
4544
return CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, CFOptionFlags(kCFRunLoopBeforeWaiting | kCFRunLoopExit), true, 0) {[weak self] observer, activity in
46-
self!.notifyQueues(.postASAP)
45+
self!.notifyQueues(.asap)
4746
}
4847
}()
4948

@@ -91,15 +90,15 @@ open class NotificationQueue: NSObject {
9190
}
9291

9392
switch postingStyle {
94-
case .postNow:
93+
case .now:
9594
let currentMode = RunLoop.current.currentMode
9695
if currentMode == nil || runloopModes.contains(currentMode!) {
9796
self.notificationCenter.post(notification)
9897
}
99-
case .postASAP: // post at the end of the current notification callout or timer
98+
case .asap: // post at the end of the current notification callout or timer
10099
addRunloopObserver(self.asapRunloopObserver)
101100
self.asapList.append((notification, runloopModes))
102-
case .postWhenIdle: // wait until the runloop is idle, then post the notification
101+
case .whenIdle: // wait until the runloop is idle, then post the notification
103102
addRunloopObserver(self.idleRunloopObserver)
104103
self.idleList.append((notification, runloopModes))
105104
}
@@ -156,7 +155,7 @@ open class NotificationQueue: NSObject {
156155
let currentMode = RunLoop.current.currentMode
157156
for queue in NotificationQueue.notificationQueueList {
158157
let notificationQueue = queue as! NotificationQueue
159-
if postingStyle == .postWhenIdle {
158+
if postingStyle == .whenIdle {
160159
notificationQueue.notify(currentMode, notificationList: &notificationQueue.idleList)
161160
} else {
162161
notificationQueue.notify(currentMode, notificationList: &notificationQueue.asapList)

Foundation/NSStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ open class OutputStream : Stream {
212212
return Stream.Status(rawValue: UInt(CFWriteStreamGetStatus(_stream)))!
213213
}
214214

215-
open class func outputStreamToMemory() -> Self {
215+
open class func toMemory() -> Self {
216216
return self.init(toMemory: ())
217217
}
218218

TestFoundation/TestNSNotificationQueue.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TestNSNotificationQueue : XCTestCase {
5555
numberOfCalls += 1
5656
}
5757
let queue = NotificationQueue.default
58-
queue.enqueue(notification, postingStyle: .postNow)
58+
queue.enqueue(notification, postingStyle: .now)
5959
XCTAssertEqual(numberOfCalls, 1)
6060
NotificationCenter.default.removeObserver(obs)
6161
}
@@ -69,9 +69,9 @@ class TestNSNotificationQueue : XCTestCase {
6969
numberOfCalls += 1
7070
}
7171
let queue = NotificationQueue.default
72-
queue.enqueue(notification, postingStyle: .postNow)
73-
queue.enqueue(notification, postingStyle: .postNow)
74-
queue.enqueue(notification, postingStyle: .postNow)
72+
queue.enqueue(notification, postingStyle: .now)
73+
queue.enqueue(notification, postingStyle: .now)
74+
queue.enqueue(notification, postingStyle: .now)
7575
// Coalescing doesn't work for the NSPostingStyle.PostNow. That is why we expect 3 calls here
7676
XCTAssertEqual(numberOfCalls, 3)
7777
NotificationCenter.default.removeObserver(obs)
@@ -87,7 +87,7 @@ class TestNSNotificationQueue : XCTestCase {
8787
numberOfCalls += 1
8888
}
8989
let notificationQueue = NotificationQueue(notificationCenter: notificationCenter)
90-
notificationQueue.enqueue(notification, postingStyle: .postNow)
90+
notificationQueue.enqueue(notification, postingStyle: .now)
9191
XCTAssertEqual(numberOfCalls, 1)
9292
NotificationCenter.default.removeObserver(obs)
9393
}
@@ -111,11 +111,11 @@ class TestNSNotificationQueue : XCTestCase {
111111
}
112112

113113
// post 2 notifications for the NSDefaultRunLoopMode mode
114-
queue.enqueue(notification, postingStyle: .postNow, coalesceMask: [], forModes: [runLoopMode])
115-
queue.enqueue(notification, postingStyle: .postNow)
114+
queue.enqueue(notification, postingStyle: .now, coalesceMask: [], forModes: [runLoopMode])
115+
queue.enqueue(notification, postingStyle: .now)
116116
// here we post notification for the NSRunLoopCommonModes. It shouldn't have any affect, because the timer is scheduled in NSDefaultRunLoopMode.
117117
// The notification queue will only post the notification to its notification center if the run loop is in one of the modes provided in the array.
118-
queue.enqueue(notification, postingStyle: .postNow, coalesceMask: [], forModes: [.commonModes])
118+
queue.enqueue(notification, postingStyle: .now, coalesceMask: [], forModes: [.commonModes])
119119
}
120120
runLoop.add(dummyTimer, forMode: .defaultRunLoopMode)
121121
let _ = runLoop.run(mode: .defaultRunLoopMode, before: endDate)
@@ -132,7 +132,7 @@ class TestNSNotificationQueue : XCTestCase {
132132
numberOfCalls += 1
133133
}
134134
let queue = NotificationQueue.default
135-
queue.enqueue(notification, postingStyle: .postASAP)
135+
queue.enqueue(notification, postingStyle: .asap)
136136

137137
scheduleTimer(withInterval: 0.001) // run timer trigger the notifications
138138
XCTAssertEqual(numberOfCalls, 1)
@@ -148,9 +148,9 @@ class TestNSNotificationQueue : XCTestCase {
148148
numberOfCalls += 1
149149
}
150150
let queue = NotificationQueue.default
151-
queue.enqueue(notification, postingStyle: .postASAP)
152-
queue.enqueue(notification, postingStyle: .postASAP)
153-
queue.enqueue(notification, postingStyle: .postASAP)
151+
queue.enqueue(notification, postingStyle: .asap)
152+
queue.enqueue(notification, postingStyle: .asap)
153+
queue.enqueue(notification, postingStyle: .asap)
154154

155155
scheduleTimer(withInterval: 0.001)
156156
XCTAssertEqual(numberOfCalls, 1)
@@ -173,15 +173,15 @@ class TestNSNotificationQueue : XCTestCase {
173173

174174
let queue = NotificationQueue.default
175175
// #1
176-
queue.enqueue(notification1, postingStyle: .postASAP, coalesceMask: .onName, forModes: nil)
176+
queue.enqueue(notification1, postingStyle: .asap, coalesceMask: .onName, forModes: nil)
177177
// #2
178-
queue.enqueue(notification2, postingStyle: .postASAP, coalesceMask: .onSender, forModes: nil)
178+
queue.enqueue(notification2, postingStyle: .asap, coalesceMask: .onSender, forModes: nil)
179179
// #3, coalesce with 1 & 2
180-
queue.enqueue(notification1, postingStyle: .postASAP, coalesceMask: .onName, forModes: nil)
180+
queue.enqueue(notification1, postingStyle: .asap, coalesceMask: .onName, forModes: nil)
181181
// #4, coalesce with #3
182-
queue.enqueue(notification2, postingStyle: .postASAP, coalesceMask: .onName, forModes: nil)
182+
queue.enqueue(notification2, postingStyle: .asap, coalesceMask: .onName, forModes: nil)
183183
// #5
184-
queue.enqueue(notification1, postingStyle: .postASAP, coalesceMask: .onSender, forModes: nil)
184+
queue.enqueue(notification1, postingStyle: .asap, coalesceMask: .onSender, forModes: nil)
185185
scheduleTimer(withInterval: 0.001)
186186
// check that we received notifications #4 and #5
187187
XCTAssertEqual(numberOfNameCoalescingCalls, 1)
@@ -200,7 +200,7 @@ class TestNSNotificationQueue : XCTestCase {
200200
let obs = NotificationCenter.default.addObserver(forName: notificationName, object: dummyObject, queue: nil) { notification in
201201
numberOfCalls += 1
202202
}
203-
NotificationQueue.default.enqueue(notification, postingStyle: .postWhenIdle)
203+
NotificationQueue.default.enqueue(notification, postingStyle: .whenIdle)
204204
// add a timer to wakeup the runloop, process the timer and call the observer awaiting for any input sources/timers
205205
scheduleTimer(withInterval: 0.001)
206206
XCTAssertEqual(numberOfCalls, 1)

TestFoundation/TestNSStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class TestNSStream : XCTestCase {
181181
var buffer = Array<UInt8>(repeating: 0, count: 12)
182182
var myString = "Hello world!"
183183
let encodedData = [UInt8](myString.utf8)
184-
let outputStream = OutputStream.outputStreamToMemory()
184+
let outputStream = OutputStream.toMemory()
185185
XCTAssertEqual(Stream.Status.notOpen, outputStream.streamStatus)
186186
outputStream.open()
187187
XCTAssertEqual(Stream.Status.open, outputStream.streamStatus)

0 commit comments

Comments
 (0)