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
  • 14,727
  • 15
  • 94
  • 183

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
  • 1,702
  • 1
  • 6
  • 20