Skip to content
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

Make the initializers of NIOThreadPoolError public #2503

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Aug 17, 2023

I tried to implement the following methods in my project to make the NIOThreadPool more user-friendly in a Swift Concurrency environment.

extension NIOThreadPool {
    public func runIfActive<T>(_ body: @escaping @Sendable () throws -> T) async throws -> T {
        return try await withCheckedThrowingContinuation { (continuation) in
            self.submit { shouldRun in
                guard case shouldRun = NIOThreadPool.WorkItemState.active else {
                    continuation.resume(throwing: NIOThreadPoolError.ThreadPoolInactive())
                    return
                }
                
                do {
                    continuation.resume(returning: try body())
                } catch {
                    continuation.resume(throwing: error)
                }
            }
        }
    }
}

However, I was unable to do so because the init of NIOThreadPoolError.ThreadPoolInactive is internal.
It would be desirable for users to be able to use it conveniently in such cases by making the init of the error public.

@Lukasa Lukasa added the semver/minor Adds new public API. label Aug 17, 2023
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This is a totally reasonable change, thanks!

@Lukasa
Copy link
Contributor

Lukasa commented Aug 17, 2023

@swift-server-bot test this please

@Lukasa Lukasa enabled auto-merge (squash) August 17, 2023 06:36
@Lukasa Lukasa merged commit 022999a into apple:main Aug 17, 2023
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants