rspeele / TaskBuilder.fs

F# computation expression builder for System.Threading.Tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add support of specifying TaskScheduler

AntyaDev opened this issue · comments

How I can set my own TaskScheduler?

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)

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

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.

@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)