Is there a more F# idiomatic way for code using TPL?

Is there a more F# idiomatic way for code using TPL?



I'm converting the following C# code to F#. (https://github.com/confluentinc/confluent-kafka-dotnet/blob/master/examples/AvroGeneric/Program.cs)


var consumeTask = Task.Factory.StartNew(() =>

while (true)

consumer.Poll(100);

);

consumeTask.Wait();



Should it be replaced by Async workflow? BTW, is it a way not to use Poll?


Async


Poll




1 Answer
1



For a more F#-idiomatic way of using Kafka in general, take a look at the Kafunk library from Jet.com. It has a nice F# API wrapping the Confluent .NET Kafka library, and in my experience it's also quite performant.



For TPL Tasks, you can use F# Async Workflows in much the same way:


let poller =
async
while true do
consumer.Poll 100


poller |> Async.Start



If you want to use a Task inside your Async Workflow, you can use Async.AwaitTak, or you can blend them together using a custom workflow, like this one.


Task


Async.AwaitTak






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj