22 questions
2
votes
1
answer
76
views
Suspend and resume F# asynchronous workflows (Async<'T>)
Is there a general way to gain external control over the execution of an arbitrary asynchronous workflow, for suspension and resumption? Akin to a CancellationToken but more like a SuspendResumeToken ...
3
votes
2
answers
570
views
F# Async Equivalent of Task.ContinueWith
I have been implementing a [<Trace>] attribute for some of our larger .NET solutions that will allow configurable analytics to be easily added to any functions/methods that are considered ...
5
votes
3
answers
418
views
Why do I have to wrap an Async<T> 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(...
0
votes
1
answer
260
views
Node js Query Async Map function is call
function(dataValue, cb) {
req.app.db.models.User.find({
_id: { $ne: dataValue._id }
}, function(err, totalUser) {
if (!err) {
...
7
votes
1
answer
735
views
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 ...
2
votes
1
answer
533
views
When calling an F# async workflow, can I avoid defining a temporary label?
Suppose I have an async data source:
let getData() = async { return [ 3.14; 2.72 ] }
I could call it using let! and a temporary label:
let showData1() = async {
let! data = getData()
data
...
8
votes
1
answer
505
views
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 ...
1
vote
1
answer
793
views
Combine Async and Option monads
In writing some code that works with a lot of nested async workflows lately I've found a pattern emerging that smells to me. A simple example:
let flip f x y = f y x
let slowInc x = async {
do! ...
3
votes
0
answers
229
views
Parallel consumption of asyncSeq using BlockingQueueAgent
Time to embarrass myself again with a lack of understanding of how concurrency works in .NET :P
I'm trying to write a function that can encapsulates creating an async workflow that takes an asyncSeq ...
8
votes
1
answer
1k
views
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
...
16
votes
2
answers
1k
views
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 [<Test>] TestFoo () =
foo
|> ...
5
votes
1
answer
2k
views
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'...
4
votes
2
answers
938
views
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 ...
1
vote
2
answers
462
views
How do I use an async workflow in a Seq.pick in F#
I am new to functional programming in general and started learning F# recently. I wanted to use an async workflow returning Async<'U option> to pick an item in a Sequence. I find a nice Seq.pick ...
15
votes
1
answer
2k
views
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 ...
2
votes
2
answers
275
views
Let! executing in sequence?
I was under the impression that let! in f# was smart enough to excute sequences of assignments in parallell.
However, the following sample displays a different behavior, assignment of a,b,c seems to ...
6
votes
2
answers
2k
views
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 ...
4
votes
3
answers
847
views
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 ...
58
votes
7
answers
36k
views
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 ...
8
votes
2
answers
1k
views
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)
...
4
votes
2
answers
1k
views
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, ...
5
votes
4
answers
1k
views
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 ...