Skip to content

Commit b49545f

Browse files
authored
Merge pull request #2253 from compnerd/and-now-i-sleep
Foundation: correct `Thread.sleep(until:)` on Windows
2 parents fb692f5 + e5ea7d8 commit b49545f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Foundation/Thread.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ open class Thread : NSObject {
106106
open class func sleep(until date: Date) {
107107
#if os(Windows)
108108
var hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
109-
// FIXME(compnerd) how to check that hTimer is not NULL?
109+
if hTimer == HANDLE(bitPattern: 0) { fatalError("unable to create timer: \(GetLastError())") }
110110
defer { CloseHandle(hTimer) }
111111

112112
// the timeout is in 100ns units
113113
var liTimeout: LARGE_INTEGER =
114-
LARGE_INTEGER(QuadPart: LONGLONG(date.timeIntervalSinceReferenceDate) * -10000000)
114+
LARGE_INTEGER(QuadPart: LONGLONG(date.timeIntervalSinceNow) * -10000000)
115115
if !SetWaitableTimer(hTimer, &liTimeout, 0, nil, nil, false) {
116116
return
117117
}

0 commit comments

Comments
 (0)