Swiftpack.co -  Package - geekaurora/CZDispatchQueue
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
geekaurora/CZDispatchQueue
Facade class encapsulating DispatchQueue: Utilize DispatchSemaphore to fulfill the control of max concurrent executions of DispatchQueue
.package(url: "https://github.com/geekaurora/CZDispatchQueue.git", from: "2.1.0")

CZDispatchQueue

Summary

  • Facade class encapsulating DispatchQueue
  • Utilize DispatchSemaphore to fulfill the control of max concurrent executions
  • Adopt two queues: Serial gateKeeperQueue and concurrent jobQueue, to ensure only one thread is blocked at most when waiting for semaphore signal
  • Limit the number of concurrently executing blocks/items in a dispatch queue. Similar as maxConcurrentOperationCount on NSOperationQueue

Screen Record

Even we triggered 1000 asynchronous tasks in CZDispatchQueue, as we set maxConcurrentCount to 3, there should have 3 concurrent executions at maximum, other tasks will be queued until slots available. As in the below screenrecord, only 3 tasks are executing at a time:

Motivation/Apple's DispatchQueue

On iOS, all DispatchQueues of one app share single thread pool with 64 threads, the resource is indeed limited, it's nice to make DispatchQueue more controllable.

How gateKeeperQueue/jobQueue works?

GitHub

link
Stars: 2
Last commit: 1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco