duemunk / Async

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch
MIT License
4.59k stars 316 forks source link

Let cancel() return if block successfully was cancelled #7

Closed duemunk closed 5 years ago

duemunk commented 10 years ago

Unfortunately the dispatch_block_testcancel() doesn't behave as expected. It just return whether or not you called dispatch_block_cancel() on a block, not if the block was successfully cancelled before being dispatched to a queue.

If the behavior of dispatch_block_testcancel() changes, the solution would look as follows:

func cancel() -> Bool {
    dispatch_block_cancel(block) // Cancel block
    let success = dispatch_block_testcancel(block) // Test if block was successfully cancelled
    return success != 0
}
duemunk commented 5 years ago

Can't be achieved.