asynchronous - How do I write this async IO C# code in F#? -


i have code:

public async task createfileasync(string filepath, byte[] bytes)     {         using (var sourcestream = system.io.file.open(filepath, filemode.openorcreate))         {             sourcestream.seek(0, seekorigin.end);             await sourcestream.writeasync(bytes, 0, bytes.length).configureawait(false);         }     } 

i want write on f#, far before can't figure out do:

module mymodule open system.io; let createfileasync (filepath: string, bytes : byte[]) =     use sourcestream = file.open(filepath, filemode.openorcreate)         |> sourcestream.seek(0, seekorigin.end);         

i have searched around there couple of concepts here , can't put them together.

you can use async { .. } workflow:

let createfileasync (filepath, bytes) = async {   use sourcestream = system.io.file.open(filepath, filemode.openorcreate)   sourcestream.seek(0, seekorigin.end)   do! sourcestream.asyncwrite(bytes, 0, bytes.length) } 

this imperative code, not different in f#.


Comments