asynchronous - F# ASync.Parallel plus main thread -


i have f# program copy files want work asynchronously. far have:

let asyncfilecopy (source, target, overwrite) =     let copyfn (source,target,overwrite) =         printfn "copying %s %s" source target         file.copy(source, target, overwrite)         printfn "copyied %s %s" source target     let fn = new func<string * string * bool, unit>(copyfn)     async.frombeginend((source, target, overwrite), fn.begininvoke, fn.endinvoke)  [<entrypoint>] let main argv =       let copyfile1 = asyncfilecopy("file1", "file2", true)     let copyfile2 = asyncfilecopy("file3", "file4", true)      let asynctask =         [copyfile1; copyfile2]          |> async.parallel       printfn "doing other stuff"      async.runsynchronously asynctask |> ignore 

which works (the files copied) not in way want. want start parallel copy operations begin copying. meanwhile, want continue doing stuff on main thread. later, want wait asynchronous tasks complete. code seems set parallel copies, other stuff, not execute copies until hits async.runsychronously.

is there way to, in effect, async.run"a"synchronously, copies started in thread pool, other stuff , later wait copies finish?

figured out:

 let asynctask =     [copyfile1; copyfile2]      |> async.parallel      |> async.startastask  let result = async.awaitiasyncresult asynctask  printfn "doing other stuff"  async.runsynchronously result |> ignore printfn "done" 

the key using startastask, awaitiasyncresult , later runsynchronously await task completion


Comments