JohnEstropia / GCDKit

Grand Central Dispatch simplified with swift.
MIT License
320 stars 39 forks source link

GCDQueue `suspend()` and `resume()` #12

Closed peyton closed 1 year ago

peyton commented 8 years ago

Hey, this PR adds thin wrappers for dispatch_suspend and dispatch_resume to GCDQueue.

One gotcha with dispatch_suspend is that it must be balanced with a call to dispatch_resume before the queue is deallocated. If we want, we can handle unbalanced suspends for the user with a thin class wrapper for custom queues that tracks suspend count and, on deinit, submits a barrier block to the target queue balancing resumes. Doing so would break clients that keep references to the underlying dispatch queue.

JohnEstropia commented 8 years ago

Thanks for the pull request!

Hmm... GCDKit used to have this but I removed it because it's confusing; it only works on custom queues: https://github.com/JohnEstropia/GCDKit/commit/eff3b65633869f485ff07ce961bad4e4b9e41a40

If we're to bring it back it should be decided how to handle global queues which does not allow suspending at all. Should we raise a fatal error/assertion? Should we fail silently?