f# - How to use FSharpx TaskBuilder with functions taking parameters -
I am currently programming with and especially. Now I wonder if it is possible to define a function that takes the parameter and takes the result like
give the dot (parameter: int) = task = taskbugder (scheduler = task scheduler. ) Work {Return! Work. Factor Match with StartNew (fun -> gt; parameter + 1)} FSharpx.Task.Run doTask (1). _ - & gt; ()
I think a function does not take any parameters to look at the source code, and a function & lt; 'A & gt; Returns
does not look like examples either.
I would be happy if someone can give advice on how to get a scenario that should run with FSHRPX or if the library should not be used like this
& lt ; Edit: I believe that I can wrap the doTask as follows
wrapperDoTask () = Dootasak (101) Match FSHRX Tasks. With roll rapper do Task _ - & gt; ()
And this can work, I am not currently with a compiler, so it is a bit of a hand cut. Does anyone have any opinion in any direction or Have I answered my question? :)
& lt; Edit2: I think this one time based on the answer needs to be edited. I especially have its PS
, I think, was well informed. I use the FSharpx TaskBuilder to interop with C #, in which, as mentioned, the tasks have been returned as hot (with some minor exceptions) It's already going on in relation to my recent question and relationship (I'll add some tags to beef the reference, maybe it is being thought of by someone else).
When I think in C # words, I have to wait for the results to wait before returning , but without blocking, I will wait for the behavior of the posterity especially I remove from
not . Results
. For example, try to think,
can read the difference What is going on in terms of which reference or scheduler or behavior or some C # is something fuzzy for me. Unfortunately, it seems that when I talk of interop, I can not ignore all the details. :)
You only need to use Task.Run
. Wait for the synchronization to complete the work on the current thread. It takes a parameter and gives you that parameter in the work factory - that is, the task < _ & Gt;
can be an instrument to create. async & lt; _ & Gt; Unlike
, work & lt; _ & Gt;
As soon as it is made, it starts to run. It is not always a desirable behavior.
You can get similar results (with a blocked wait to complete the task) with (doTask 101). Result,
, but I think that is more idiotic for work .run
F #, instead of raising an exception, an result
Uses Return Type. Depending on the situation, it is better, but it can be logical that, in the case of circumstances, but in simple cases, a special result in my experience is more consistent than the exceptions.
Here is another issue that you should avoid blocking waiting ( Task.Run
, . Wait ()
, .
) as much as you can. (Ideally, you have only one of those people who is at the top level of your program.)
P s. It is beyond the scope of the question, but your doTask
function looks awkward work {return! Work. Factor Startup (...)}
is equivalent to the job. Factor Start (...)
. You probably want to do this function {return parameter + 1}
.
Edit
Therefore, in response to editing OP's question :) If you need to wait for behavior from C #, you just < Need to use code>! ...
. Like this:
work {come on! X = some tasks 1 2 3 return x + 5}
Comments
Post a Comment