WorkItemState
The state of the WorkItem
.
enum WorkItemState
The state of the WorkItem
.
enum WorkItemState
import NIOPosix
final class NIOThreadPool
A thread pool that should be used if some (kernel thread) blocking work needs to be performed for which no non-blocking API exists.
case active
The WorkItem
is active now and in process by the NIOThreadPool
.
case cancelled
The WorkItem
was cancelled and will not be processed by the NIOThreadPool
.
convenience init(numberOfThreads: Int)
Initialize a NIOThreadPool
thread pool with numberOfThreads
threads.
static var singleton: NIOThreadPool { get }
A globally shared, singleton NIOThreadPool
.
static func _makePerpetualStartedPool(numberOfThreads: Int, threadNamePrefix: String) -> NIOThreadPool
Create a NIOThreadPool
that is already started, cannot be shut down and must not be deinit
ed.
let numberOfThreads: Int
func _start(threadNamePrefix: String)
func runIfActive<T>(_ body: @escaping () throws -> T) async throws -> T where T : Sendable
Runs the submitted closure if the thread pool is still active, otherwise throw an error. The closure will be run on the thread pool, such that we can do blocking work.
@preconcurrency func runIfActive<T>(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture<T> where T : Sendable
Runs the submitted closure if the thread pool is still active, otherwise fails the promise. The closure will be run on the thread pool so can do blocking work.
func shutdownGracefully() async throws
Shuts down the thread pool gracefully.
@preconcurrency func shutdownGracefully(_ callback: @escaping (Error?) -> Void)
@preconcurrency func shutdownGracefully(queue: DispatchQueue, _ callback: @escaping (Error?) -> Void)
Gracefully shutdown this NIOThreadPool
. All tasks will be run before shutdown will take place.
func start()
Start the NIOThreadPool
if not already started.
@preconcurrency func submit(_ body: @escaping WorkItem)
Submit a WorkItem
to process.
func syncShutdownGracefully() throws
typealias WorkItem = (WorkItemState) -> Void
The work that should be done by the NIOThreadPool
.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.