mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: SwiftNIO lacks a convenience API for performing blocking IO / tasks. As this is a fairly common task it then requires the clients to make ad hoc implementations that address this requirement. Modifications: Extension to DispatchQueue with the following method to schedule a work item to the `DispatchQueue` and return and `EventLoopFuture` for the result returned: - `asyncWithFuture<NewValue>(eventLoop: EventLoop, _ callbackMayBlock: @escaping () throws -> NewValue) -> EventLoopFuture<NewValue>` Added new unit tests for this function both when the promise succeeds and fails. Extention to EventLoopFuture with the following public functions: - `flatMapBlocking<NewValue)(onto queue DispatchQueue, _ callbackMayBlock: @escpaing (Value) throws -> NewValue) -> EventLoopFuture<NewValue>` - `whenSuccessBlocking(onto queue DispatchQueue, _ callbackMayBlock: @escaping (Value) -> Void) -> EventLoopFuture<NewValue>` - `whenFailureBlocking()onto queue DispatchQueue, _ callbackMayBlock: @escaping (Error) -> Void) -> EventLoopFuture<NewValue>` - `whenCompleteBlocking(onto queue DispatchQueue, _ callbackMayBlock: @escaping (Result<Value, Error>) -> Void) -> EventLoopFuture<NewValue>` These functions may all be called safely with callbacks that perform blocking IO / Tasks. Added new unit tests to EventLoopFutureTest.swift for each new function. Result: New public API for `EventLoopFuture` that allows scheduling of blocking IO / Tasks.