public 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.
When using NIO it is crucial not to block any of the
EventLoops as that
leads to slow downs or stalls of arbitrary other work. Unfortunately though
there are tasks that applications need to achieve for which no non-blocking
APIs exist. In those cases
NIOThreadPool can be used but should be
treated as a last resort.
NoteThe prime example for missing non-blocking APIs is file IO on UNIX. The OS does not provide a usable and truly non-blocking API but with
NonBlockingFileIONIO provides a high-level API for file IO that should be preferred to running blocking file IO system calls directly on
NIOThreadPool. Under the covers
NIOThreadPoolon all currently supported platforms though.
Gracefully shutdown this
NIOThreadPool. All tasks will be run before shutdown will take place.
public func shutdownGracefully(queue: DispatchQueue, _ callback: @escaping (Error?) -> Void)
DispatchQueueused to executed the callback
The function to be executed once the shutdown is complete.
NIOThreadPoolthread pool with
public init(numberOfThreads: Int)
The number of threads to use for the thread pool.
NIOThreadPoolif not already started.
public func start()
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.
The closure which performs some blocking work to be done on the thread pool.
promisefulfilled with the result (or error) of the passed closure.