hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Async question

Last post 07-07-2008, 17:20 by dsyme. 3 replies.
Sort Posts: Previous Next
  •  07-05-2008, 8:00 6297

    Async question

    Hi,

    I have a batch of jobs that I want to execute in parallel, but the jobs come in at different points in time and at the end I need to wait until all jobs are finished (though I don't need their results). What's the most elegant way to do this in F#? Getting an AsyncFuture for each job and then synchronizing by accessing the Value property of all futures one after another?

    Thanks in advance for any hint.

    Best regards,
      Stephan

  •  07-05-2008, 20:19 6298 in reply to 6297

    Re: Async question

    So you don't know the jobs ahead of time?

    If there really is a phase transition from "jobs coming in" to "all jobs are in, now wait for all results" then collecting a global set of AsyncFuture objects and synchronizing on them sounds OK.

    If jobs continue to come in then you may want to have the jobs send their results to a dedicated agent (MailboxProcessor) that collects and aggregates them and either processes requests for the aggreagate reults or fires events on the GUI thread (if there is one) as new results come in.

    Regards

    don

     

  •  07-06-2008, 1:12 6299 in reply to 6298

    Re: Async question

    Yes, the jobs depend on the input, so I don't know about them in advance.

    Basically, I have a long running sequential computation which discovers sub-computations that can be run in parallel. I'd like to start working on the sub-computations as soon as I discover them to fully exploit any latent parallelism.

    Thanks for the help,
      Stephan

  •  07-07-2008, 17:20 6321 in reply to 6299

    Re: Async question

    Right - futures are perfect for this (use either the F# Async ones or the TPL ones)

    don

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems