https://kotlinlang.org logo
#ktor
Title
# ktor
b

bitkid

09/05/2019, 10:01 PM
hi! how can i handle a cancelled request? especially cancel coroutine methods called within a request?
d

Dominaezzz

09/05/2019, 10:39 PM
Are you implementing an engine?
c

cy

09/06/2019, 9:52 AM
Just launch your coroutines in a request coroutine scope. Once request get cancelled, the whole coroutine scope will be cancelled as well
```
Copy code
get("/") {
    launch { 
        // this will be cancelled if failed
    }
}
b

bitkid

09/06/2019, 11:01 AM
i have this datasource which has it's own threadpool .. so in the datasource i have a method
suspend getData() {withContext(pool.asDispacther()) { do something}}
do i have to add the scope to withContext?
getData will be called in get("/") {}
c

cy

09/06/2019, 11:21 AM
No, you don't need anything
However, note that immediate cancellation is not possible during blocking operations such as reading from a socket