Concurrency utilities for Swift
A set of concurrency utility classes used by Uber. These are largely inspired by the equivalent java.util.concurrent package classes.
AtomicBool
Provides locking-free synchronization of a mutable Bool
. It provides higher performance than using locks to ensure thread-safety and synchronization correctness.
AtomicInt
Provides locking-free synchronization of a mutable Int
. It provides higher performance than using locks to ensure thread-safety and synchronization correctness.
AtomicReference
Provides locking-free synchronization of a mutable object reference. It provides higher performance than using locks to ensure thread-safety and synchronization correctness.
CountDownLatch
A utility class that allows coordination between threads. A count down latch starts with an initial count. Threads can then decrement the count until it reaches zero, at which point, the suspended waiting thread shall proceed. A CountDownLatch
behaves differently from a DispatchSemaphore
once the latch is open. Unlike a semaphore where subsequent waits would still block the caller thread, once a CountDownLatch
is open, all subsequent waits can directly passthrough.
ConcurrentSequenceExecutor
An execution utility that executes sequences of tasks and returns the final result in a highly concurrent environment.
SerialSequenceExecutor
A debugging executor that executes sequences of tasks and returns the final result serially on the caller thread.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with dylib frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Swift-Concurrency into your Xcode project using Carthage, specify it in your Cartfile
:
github "https://github.com/uber/swift-concurrency.git" ~> 0.4.0
Run carthage update
to build the framework and add the built Concurrency.framework
into your Xcode project, by following the instructions
If you prefer not to use Carthage, you can integrate Swift-Concurrency into your project manually, by adding the source files.
First fetch the dependencies:
$ swift package fetch
You can then build from the command-line:
$ swift build
Or create an Xcode project and build using the IDE:
$ swift package generate-xcodeproj
From command-line.
$ swift test
Or you can follow the steps above to generate a Xcode project and run tests within Xcode.
If you like Needle, check out other related open source projects from our team: