Home:ALL Converter>How to ignore the return value of an Async function in an Async block?

How to ignore the return value of an Async function in an Async block?

Ask Time:2018-06-08T22:04:58         Author:ca9163d9

Json Formatter

The m1 and m2 in the following functions have compiling errors.

let m p = async { return p * 2 }
let m1 () = async { do! m 2 } // ERR: was expected 'int' but here has type 'unit'
let m2 () = async { do! m 2 |> ignore } // ERR: expecting 'Async<int>->Async<'a>' but given 'Async<int>->unit'

m is called at the last line. How to ignore its return value? Is the following the only way (will executing of it be optimized by the compiler?)?

let m1 () = 
    async { 
      let! x = m 2 
      () 
    }

Author:ca9163d9,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762436/how-to-ignore-the-return-value-of-an-async-function-in-an-async-block
yy