Skip to content

waitUntilExit: ignore RunLoop.run()'s return value #4740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ void __CFInitialize(void) {
if (!__CFInitialized && !__CFInitializing) {
__CFInitializing = 1;

#if __HAS_DISPATCH__
#if __HAS_DISPATCH__ && !TARGET_OS_MAC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would use the deployment version - but this is still forwards/backwards incompatible. @parkera - any thoughts? I'm tempted to say we merge this even with that limitation as this is blocking PRs for other platforms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is designed to go with the corresponding libdispatch, so if we are making a change to both (or a change to dispatch has already been made), they would go together into a Swift release.

// libdispatch has to be initialized before CoreFoundation, so to avoid
// issues with static initializer ordering, we are doing it explicitly.
libdispatch_init();
Expand Down
15 changes: 9 additions & 6 deletions Sources/Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1134,14 +1134,17 @@ open class Process: NSObject {
open func waitUntilExit() {
let runInterval = 0.05
let currentRunLoop = RunLoop.current
let checkRunLoop : () -> Bool = (currentRunLoop == self.runLoop)
? { currentRunLoop.run(mode: .default, before: Date(timeIntervalSinceNow: runInterval)) }
: { currentRunLoop.run(until: Date(timeIntervalSinceNow: runInterval)); return true }

// update .runLoop to allow early wakeup.
let runRunLoop : () -> Void = (currentRunLoop == self.runLoop)
? { currentRunLoop.run(mode: .default, before: Date(timeIntervalSinceNow: runInterval)) }
: { currentRunLoop.run(until: Date(timeIntervalSinceNow: runInterval)) }
// update .runLoop to allow early wakeup triggered by terminateRunLoop.
self.runLoop = currentRunLoop
while self.isRunning && checkRunLoop() {}


while self.isRunning {
runRunLoop()
}

self.runLoop = nil
self.runLoopSource = nil
}
Expand Down