rspeele / TaskBuilder.fs

F# computation expression builder for System.Threading.Tasks
Creative Commons Zero v1.0 Universal
235 stars 27 forks source link

add support of specifying TaskScheduler #22

Closed AntyaDev closed 5 years ago

AntyaDev commented 5 years ago

How I can set my own TaskScheduler?

rspeele commented 5 years ago

It's out of scope of this library. Something like the below may be what you're looking for:

Task.Factory.StartNew((fun () -> task { (* ... your F# code here ... *) }), CancellationToken.None, TaskCreationOptions.None, yourSchedulerHere)
AntyaDev commented 5 years ago

@rspeele yes I have tried it, but I assume that next continuation is using TaskScheduler.Default which is not TaskScheduler.Current

rspeele commented 5 years ago

Sorry, didn't see this. This library does not use Task.ContinueWith, it is equivalent in behavior to a C# async method. So I don't believe it applies, any more than you would try to set the scheduler for the next part of an async method after an await.

AntyaDev commented 5 years ago

@rspeele about your example

Task.Factory.StartNew((fun () ->
 // this will be runned on yourSchedulerHere , it's clear
 task { 
     (* ... your F# code here ... *) // is this code will be runned on yourSchedulerHere?
}), CancellationToken.None, TaskCreationOptions.None, yourSchedulerHere)