# Chapter 4: How to 'cancel the fetch request with NSAsynchronousFetchResult’s cancel() method.'

**URL:** <https://forums.kodeco.com/t/chapter-4-how-to-cancel-the-fetch-request-with-nsasynchronousfetchresult-s-cancel-method/13651>\
**Category:** Core Data by Tutorials\
**Created:** [April 20, 2016, 10:23am UTC](https://forums.kodeco.com/t/chapter-4-how-to-cancel-the-fetch-request-with-nsasynchronousfetchresult-s-cancel-method/13651 "2016-04-20T10:23:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drwhy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/drwhy/32/81494_2.png) [@drwhy](https://forums.kodeco.com/u/drwhy)\
**Post date:** [April 20, 2016, 10:23am UTC](https://forums.kodeco.com/t/chapter-4-how-to-cancel-the-fetch-request-with-nsasynchronousfetchresult-s-cancel-method/13651/1 "2016-04-20T10:23:14Z")

</div>

In this chapter, you mention as an aside that it is possible to cancel the fetch request with  
NSAsynchronousFetchResult’s cancel() method. I can’t figure out, however, what the NSAsync…Result value is. Could you please provide a code example of how to cancel the request from within the do try block?

---

<div class="post-metadata">

**Author:** ![izzywizz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/izzywizz/32/81494_2.png) [@izzywizz](https://forums.kodeco.com/u/izzywizz)\
**Post date:** [August 24, 2017, 9:01am UTC](https://forums.kodeco.com/t/chapter-4-how-to-cancel-the-fetch-request-with-nsasynchronousfetchresult-s-cancel-method/13651/2 "2017-08-24T09:01:55Z")

</div>

I am just working my way through this as well but the way to do it which I found was casting the result to a NSPersistentStoreAsynchronousResult, so for example

```
  let result = try coreDataStack.managedContext.execute(asyncFetchRequest) as! NSPersistentStoreAsynchronousResult
  result.cancel()

```

Or you can actually cancel the request from within the closure itself, the best way to do it is to keep track of the progress and if some condition comes to pass or its taking a while is to cancel it I guess,  
There is a good blog on it here: [Asynchronous core data requests](https://www.allaboutswift.com/dev/2016/5/29/asynchronous-core-data-requests)
