Questions tagged [async-workflow]

Support in F# for performing computations asynchronously, that is, without blocking execution of other work. For example, asynchronous computations can be used to write applications that have UIs that remain responsive to users as the application performs other work.

22 questions
56
votes
7 answers

Is there an async version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet?

Is there an asynchronous version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet? I'd like to use them in an F# async block, and it'd be nice to have a version that can be called with AsyncCallbacks. Problem is I'm trying to suck…
James Moore
  • 8,636
  • 5
  • 71
  • 90
16
votes
2 answers

How to get a useful stacktrace when testing F# async workflows

I'd like to test the following async workflow (with NUnit+FsUnit): let foo = async { failwith "oops" return 42 } I wrote the following test for it: let [] TestFoo () = foo |> Async.RunSynchronously |> should equal 42 Since foo…
stmax
  • 6,506
  • 4
  • 28
  • 45
15
votes
1 answer

What is the Scala equivalent of F#'s async workflows?

What is the Scala equivalent of F#'s async workflows? For example, how would following F# snippet translate to idiomatic Scala? open System.Net open Microsoft.FSharp.Control.WebExtensions let urlList = [ "Microsoft.com",…
pharoah 121
  • 151
  • 3
8
votes
2 answers

Best practices to parallelize using async workflow

Lets say I wanted to scrape a webpage, and extract some data. I'd most likely write something like this: let getAllHyperlinks(url:string) = async { let req = WebRequest.Create(url) let! rsp = req.GetResponseAsync() use…
Juliet
  • 80,494
  • 45
  • 196
  • 228
8
votes
1 answer

async computation doesn't catch OperationCancelledException

I'm trying to make an asynchronous web request to a URL that will return if the request takes too long. I'm using the F# asynchronous workflow and the System.Net.Http library to do this. However, I am unable to catch the…
WiseGuyEh
  • 18,584
  • 1
  • 20
  • 20
8
votes
1 answer

Async.Catch doesnt work on OperationCanceledExceptions

I use Async.Catch to handle exceptions thrown by async workflows: work |> Async.Catch |> Async.RunSynchronously |> fun x -> match x with | Choice1Of2 _ -> () // success | Choice2Of2 ex -> // failure, handle exception Today I…
stmax
  • 6,506
  • 4
  • 28
  • 45
7
votes
1 answer

ConfigureAwait(false) in F#

I am using a library which has been written in C# and uses the async/await pattern. In C# I can await something by calling it with ConfigureAwait(false) but when I use the library from F# I don't see a way of doing the same thing? Currently I do…
dustinmoris
  • 3,195
  • 3
  • 25
  • 33
6
votes
2 answers

F# async web request, handling exceptions

I'm trying to use async workflows in F# to fetch several web requests. However, some of my requests are occasionally returning errors (e.g. http 500), and I don't know how to handle this. It appears like my F# program gets stuck in an infinite loop…
jessicah
  • 945
  • 10
  • 15
5
votes
3 answers

Why do I have to wrap an Async into another async workflow and let! it?

I'm trying to understand async workflows in F# but I found one part that I really don't understand. The following code works fine: let asynWorkflow = async{ let! result = Stream.TryOpenAsync(partition) |> Async.AwaitTask return result }…
KCT
  • 287
  • 1
  • 10
5
votes
4 answers

Parallelize code in nested loops

You always hear that functional code is inherently easier to parallelize than non-functional code, so I decided to write a function which does the following: Given a input of strings, total up the number of unique characters for each string. So,…
Juliet
  • 80,494
  • 45
  • 196
  • 228
5
votes
1 answer

F# Async.RunSynchronously with timeout and cancellationToken

When calling Async.RunSynchronously with a timeout and a CancellationToken, the timeout value seems to be ignored. I can work around this by calling CancelAfter on the CancellationToken, but ideally I'd like to be able to distinguish between…
Joe Taylor
  • 2,145
  • 1
  • 19
  • 35
4
votes
2 answers

Unexpected behavior with exception handling in async, possible bug?

I have stumbled upon a problem when calling a nested Async which happens to be null. An exception is raised but it can't be catched with any of the normal exception handling methods Async workflows provide. The following is a simple test which…
Samuel Otter
  • 608
  • 3
  • 7
4
votes
2 answers

Async Workflows in F#

I am a C# programmer, but I have a question about Async Workflows in F#. Supposing I have the following class in a C# class library: class File { IAsyncResult BeginReadAll(string fileName, AsyncCallback callback, object state){} string…
skb
  • 30,624
  • 33
  • 94
  • 146
4
votes
3 answers

How to keep asynchronous parallel program code manageable (for example in C++)

I am currently working on a server application that needs to control a collection devices over a network. Because of this, we need to do a lot of parallel programming. Over time, I have learned that there are three approaches to communication…
Dimitri C.
  • 21,861
  • 21
  • 85
  • 101
3
votes
2 answers

F# Async Equivalent of Task.ContinueWith

I have been implementing a [] attribute for some of our larger .NET solutions that will allow configurable analytics to be easily added to any functions/methods that are considered important. I'm using Fody and the MethodBoundaryAspect to…
Aaron M. Eshbach
  • 6,380
  • 12
  • 22
1
2