Venkataramanan Parameswaran
08/17/2022, 5:03 PMmkrussel
08/17/2022, 5:13 PM@Throws
it can contain that.
Otherwise it will only be the CancelationException. I’m not sure how that would trigger, since it doesn’t seem like there is anything that could cancel it.
Only thing I can thing of is awaiting on an async from another scope and that scope was canceled or the async itself was canceled.Venkataramanan Parameswaran
08/17/2022, 5:16 PM@Throws
but what is the use of this annotation here...?mkrussel
08/17/2022, 5:53 PMRick Clephas
08/17/2022, 7:42 PM@Throws
annotation are passed to ObjC/Swift. Any other exception will terminate the program. This behaviour is explained in more detail in the docs.
Without the @Throws
annotation you’ll likely never receive an error since you can’t cancel the suspend function from Swift. Though you will receive `CancelationException`s thrown by e.g. withTimeout
.
FYI if you want more control over your suspend functions you should instead use some kind of wrapper function that exposes an option to cancel the function.
Or use a library that does this for you. Like the one I developed: https://github.com/rickclephas/KMP-NativeCoroutines