Can I explicitly check for cancellation or completion of asynchronous computation?

I have an asynchronous calculation like the following (see inline comments):

async { //... do! Async.Sleep(100) //cancellation may happen during sleep //... but isn't checked at the end of the sleep, so regular, non-async computations are executed here } 

In order to force the revocation check / complete the entire asynchronous calculation before reaching the β€œregular” part of the calculation, I insert an effective no-op do! Async.Sleep(1) do! Async.Sleep(1) immediately after do! Async.Sleep(100) do! Async.Sleep(100) . Is there a cleaner way to do this? Maybe even something like do! Async.Nop do! Async.Nop .

+6
source share
1 answer

How about something like this:

 let nop = async.Return () 

Then you can use it like:

 async { // ... do! Async.Sleep 100 do! nop } 
+5
source

Source: https://habr.com/ru/post/953396/