Running async c # method in f # workflow

I am trying to get the code below to work in the F # async workflow, but I am getting the error "Unexpected character"} in the expression. I am new to both F # and async in general. What I miss here.

let someFunction (req : HttpRequestMesssage) a b = 

    // code
    async{
        let! readToProvider =
            req.Content.ReadAsMultipartAsync(provider)
            |> Async.AwaitIAsyncResult 

    } |> Async.RunSynchronously

    req.CreateResponse(HttpStatusCode.OK)
+4
source share
2 answers

I am worried that my previous answer was not quite what you want. What I put just caused a compilation error. But one thing about this is that it does not start asynchronously. Task.Waitand Async.RunSynchronouslywill block the current thread until the operation is completed.

, , , , , async, async op . ,

let someFunction (req : HttpRequestMesssage) a b = 
  async {
    let! readToProvider = (req.Content.ReadAsMultipartAsync provider) |> Async.AwaitIAsyncResult 
    return req.CreateResponse HttpStatusCode.OK
  }

, Async<Response>. , , , , - .

, -, , (, async Task , .net - #), . , async op, do! someFunction ..., . , , someFunction ... |> Async.RunSynchronously. , . let someFunctionSync ... = someFunction ... |> Async.RunSynchronously, .

, .

+6

. , async let!. return! do! ... |> Async.Ignore, .

F # ( , ) let.

, , , , ( ).

req.Content.ReadAsMultipartAsync provider
  |> Async.AwaitIAsyncResult 
  |> Async.Ignore
  |> Async.RunSynchronously
req.CreateResponse HttpStatusCode.OK

, , "", , Async.RunSynchronously:

(req.Content.ReadAsMultipartAsync provider).Wait()
+5

All Articles