title: How to cancel an Asynchronous function in Swift
body: <p>In swift, what is the common practice to cancel an aync execution?</p>
  <p>Using this example, which execute the closure asynchronously,
  what is the way to cancel the async function?</p>
  <pre><code>func getSumOf(array:[Int], handler: @escaping ((Int)-&gt;Void)) {
      //step 2
      var sum: Int = 0
      for value in array {
          sum += value
      }
      //step 3
      Globals.delay(0.3, closure: {
          handler(sum)
      })
  }
  
  func doSomething() {
      //setp 1
      self.getSumOf(array: [16,756,442,6,23]) { [weak self](sum) in
          print(sum)
          //step 4, finishing the execution
      }
  }
  //Here we are calling the closure with the delay of 0.3 seconds
  //It will print the sumof all the passed numbers.
  </code></pre>