0

Grand Central Dispatch (GCD) function they can utilize but once it's set up, these calls can not be easily cancelled.

How could we stop it such as a custom method "cancellable_dispatch_after"

casillas
  • 16,351
  • 19
  • 115
  • 215

1 Answers1

0

If you are trying to find a way to cancel asynchronous operations using GCD, you should use DispatchWorkItem. It allows you to do the following:

import Dispatch

let task = DispatchWorkItem {
    //Do some stuff
}
DispatchQueue.main.async(execute: task)
task.cancel()

Obviously, you wouldn't do this exactly, but I believe it shows how to do what you want.

Hope this helps!

Sam
  • 2,350
  • 1
  • 11
  • 22