Package
AsyncKit
Provides a set of utilities for working with EventLoopFutures and other pre-Concurrency support APIs.
Overview
AsyncKit is a legacy package; its use is not recommended in new projects.
AsyncKit provides a number of extensions to both Swift’s Concurrency primitives and NIO’s futures to make working with them easier. The long-term goal is to migrate away from this package as Swift Concurrency adds support for working in an asynchronous environment easy.
See references below for usage details.
Topics
Legacy connection pools
EventLoopConnectionPoolHolds a collection of active connections that can be requested and later released back into the pool.EventLoopGroupConnectionPoolHolds a collection of connection pools for eachEventLoopon anEventLoopGroup.ConnectionPoolSourceSource of new connections forEventLoopGroupConnectionPool.ConnectionPoolItemItem managed by a connection pool.ConnectionPoolErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding state.ConnectionPoolTimeoutErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding timeouts.
Optionals
strictMap(_:_:)Given one or more optionals as inputs, checks whether each input isnil. If any input isnil,nilis immediately returned as an overall results. If all of the inputs have values, thetransformcallback is invoked with all of the unwrapped values as parameters.strictMap(_:_:_:)strictMap(_:_:)over 2 optionals.strictMap(_:_:_:_:)strictMap(_:_:)over 3 optionals.strictMap(_:_:_:_:_:)strictMap(_:_:)over 4 optionals.strictMap(_:_:_:_:_:_:)strictMap(_:_:)over 5 optionals.strictMap(_:_:_:_:_:_:_:)strictMap(_:_:)over 6 optionals.strictMap(_:_:_:_:_:_:_:_:)strictMap(_:_:)over 7 optionals.strictMap(_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 8 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 9 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 10 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 11 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 12 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 13 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 14 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 15 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 16 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 17 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 18 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 19 optionals.strictMap(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)strictMap(_:_:)over 20 optionals.
EventLoop and EventLoopGroup
flatten(_:)Returns a newEventLoopFuturethat succeeds only when all the provided futures succeed. The newEventLoopFuturecontains an array of results, maintaining same ordering as the futures.flatten(_:)Returns a newEventLoopFuturethat succeeds only when all the provided futures succeed, ignoring the resolved values.future()Creates a new, succeededEventLoopFuturefrom the worker’s event loop with aVoidvalue.future(error:)Creates a new, failedEventLoopFuturefrom the worker’s event loop.future(_:)Creates a new, succeededEventLoopFuturefrom the worker’s event loop.future(result:)Creates a newFuturefrom the worker’s event loop, succeeded or failed based on the inputResult.tryFuture(_:)An alternate name for this would befuture(catching:), but with that name, trailing closure syntax just looks likeel.future { ... }, which does not indicate to readers of the code that it is the error-capturing version. Since such an indication is highly desirable, a slightly less idiomatic name is used instead.
EventLoopFuture
EventLoopFutureQueueAllows you to queue closures that produce anEventLoopFuture, so each future only gets run if the previous ones complete, succeed, or fail.mapEach(_:)Gets the value of a key path for each element in the sequence that is wrapped by anEventLoopFuture.mapEach(_:)Calls a closure on each element in the sequence that is wrapped by anEventLoopFuture.mapEachCompact(_:)Gets the optional value of a key path for each element in the sequence that is wrapped by anEventLoopFuture.mapEachCompact(_:)Calls a closure, which returns anOptional, on each element in the sequence that is wrapped by anEventLoopFuture.mapEachFlat(_:)Gets the collection value of a key path for each element in the sequence that is wrapped by anEventLoopFuture, combining the results into a single result collection.mapEachFlat(_:)Calls a closure which returns a collection on each element in the sequence that is wrapped by anEventLoopFuture, combining the results into a single result collection.flatMapEach(on:_:)Calls a closure, which returns anEventLoopFuture, on each element in a sequence that is wrapped by anEventLoopFuture. No results from each future are expected.flatMapEach(on:_:)Calls a closure, which returns anEventLoopFuture, on each element in a sequence that is wrapped by anEventLoopFuture.flatMapEachCompact(on:_:)Calls a closure, which returns anEventLoopFuture<Optional>, on each element in a sequence that is wrapped by anEventLoopFuture.flatMapEachThrowing(_:)Calls a closure on each element in the sequence that is wrapped by anEventLoopFuture.flatMapEachCompactThrowing(_:)Calls a closure, which returns anOptional, on each element in the sequence that is wrapped by anEventLoopFuture.sequencedFlatMapEach(_:)An overload ofsequencedFlatMapEach(_:)which returns aVoidfuture instead of[Void]when the result type of the transform closure isVoid.sequencedFlatMapEach(_:)A variant form offlatMapEach(on:_:)which guarantees:sequencedFlatMapEachCompact(_:)Variant ofsequencedFlatMapEach(_:)which providescompactMap()semantics by allowing result values to benil. Such results are not included in the output array.whenTheySucceed(_:_:file:line:)Returns a newEventLoopFuturethat succeeds only if all of the provided fs succeed. The newEventLoopFuturewill contain all of the values fulfilled by the fs.whenTheySucceed(_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 3.whenTheySucceed(_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 4.whenTheySucceed(_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 5.whenTheySucceed(_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 6.whenTheySucceed(_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 7.whenTheySucceed(_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 8.whenTheySucceed(_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 9.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 10.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 11.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 12.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 13.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 14.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 15.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 16.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 17.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 18.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 19.whenTheySucceed(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:file:line:)whenTheySucceed(_:_:file:line:)of order 20.guard(_:else:)Guards that the future’s value satisfies the callback’s condition or fails with the given error.flatMapAlways(file:line:_:)When the currentEventLoopFuturereceives any result, run the provided callback, which will provide a newEventLoopFuture. Essentially combines the behaviors of.always(_:)and.flatMap(file:line:_:).nonempty(orError:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, the provided error is thrown.nonemptyMap(_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with an empty array as its value is returned. Otherwise, the provided normalmap()callback is invoked. The callback’s return type must be anArrayor aRangeReplaceableCollection.nonemptyMap(or:_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with the provided alternate value is returned. Otherwise, the provided normalmap()callback is invoked.nonemptyFlatMapThrowing(_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with an empty array as its value is returned. Otherwise, the provided normalflatMapThrowing()callback is invoked. The callback’s return type must be anArrayor aRangeReplaceableCollection.nonemptyFlatMapThrowing(or:_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with the provided alternate value is returned. Otherwise, the provided normalflatMapThrowing()callback is invoked.nonemptyFlatMap(_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with an empty array as its value is returned. Otherwise, the provided normalflatMap()callback is invoked. The callback’s returned future must have a value type that is anArrayor aRangeReplaceableCollection.nonemptyFlatMap(or:_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, a new future with the provided alternate value is returned. Otherwise, the provided normalflatMap()callback is invoked.nonemptyFlatMap(orFlat:_:)Checks that the future’s value (if any) returnsfalsefor.isEmpty. If the check fails, the provided alternate future is returned. Otherwise, the provided normalflatMap()callback is invoked.optionalMap(_:)Calls a closure on an optional value that is wrapped in anEventLoopFutureif it exists.optionalFlatMap(_:)Calls a closure on an optional value in anEventLoopFutureif it exists.optionalFlatMap(_:)Calls a closure that returns an optional future on an optional value in anEventLoopFutureif it exists.optionalFlatMapThrowing(_:)Calls a throwing closure on an optional value in anEventLoopFutureif it exists.transform(to:)Maps the current future to contain the new type. Errors are carried over, successful (expected) results are transformed into the given instance.transform(to:)Maps the current future to contain the new type. Errors are carried over, successful (expected) results are transformed into the given instance.tryFlatMap(file:line:_:)
EventLoopFuture operators
+(_:_:)Adds two futures and produces their sum+(_:_:)Adds two futures and produces their sum+=(_:_:)Adds two futures and stores the result in the left-hand-side variable+=(_:_:)Adds two futures and stores the result in the left-hand-side variable*(_:_:)Multiplies two futures and produces their product*=(_:_:)Multiplies two futures and stores the result in the left-hand-side variable%(_:_:)Returns the remainder of dividing the first future by the second%=(_:_:)Divides the first future by the second and stores the remainder in the left-hand-side variable<(_:_:)Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument<=(_:_:)Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument>(_:_:)Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument>=(_:_:)Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument<<(_:_:)Returns the result of shifting a future’s binary representation the specified number of digits to the left<<=(_:_:)Stores the result of shifting a future’s binary representation the specified number of digits to the left in the left-hand-side variable>>(_:_:)Returns the result of shifting a future’s binary representation the specified number of digits to the right>>=(_:_:)Stores the result of shifting a future’s binary representation the specified number of digits to the right in the left-hand-side variable&(_:_:)Returns the result of performing a bitwise AND operation on the two given futures&=(_:_:)Stores the result of performing a bitwise AND operation on the two given futures in the left-hand-side variable|(_:_:)Returns the result of performing a bitwise OR operation on the two given futures|=(_:_:)Stores the result of performing a bitwise OR operation on the two given futures in the left-hand-side variable^(_:_:)Returns the result of performing a bitwise XOR operation on the two given futures^=(_:_:)Stores the result of performing a bitwise XOR operation on the two given futures in the left-hand-side variable~(_:)Returns the result of performing a bitwise NOT operation on the given future