Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easiest option is to use <code>Async.StartChild</code>. This primitve starts an asynchronous operation in background (in a thread pool) and returns a "token" that can be used to wait for a completion of the operation. This doesn't block the workflow, so you can then continue running other operations:</p> <pre><code>let productOfIncrements x y = async { // Start the 'incr x' operation in background let! x1Op = async {return incr x} |&gt; Async.StartChild // Continue doing other work // (synchronously since it takes the same time as the above.) let y1 = incr y // Now wait for the result of 'incr x' (if it is still running) let! x1 = x1Op // return the product (just call the function synchronously) return product x1 y1 } </code></pre> <p>If the two operations return the same type, then you can also use <code>Async.Parallel</code>, which composes multiple operations to run in parallel.</p> <p>If you're working with purely CPU-bound computations and you need to create a large number of them, then you can also use .NET <code>Tasks</code> directly (see for example <a href="http://tomasp.net/blog/fsharp-parallel-plinq.aspx" rel="nofollow">this article</a>). Tasks are more efficient, but are not as elegant to use (and don't support asynchronous waiting nicely).</p> <p>As a side-note, the term <em>pipeline</em> is usually used (at least in F# or .NET world) for a more complicated thing - For example, say you have a series of steps that depend on each other. When processing multiple inputs, you can run the steps in parallel (and still limit the total paralellism). This can be done using F# async workflows too - see <a href="http://tomasp.net/blog/parallel-extra-image-pipeline.aspx" rel="nofollow">for example this article</a>. There is also a <a href="https://github.com/7sharp9/pipelets" rel="nofollow">framework named pipelets</a> that implements the concept.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload