-
Notifications
You must be signed in to change notification settings - Fork 830
add StartImmediate method to the MailboxProcessor (#11370) #11515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dsyme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test e.g. in tests\fsharp\core\controlMailbox\test.fsx
src/fsharp/FSharp.Core/mailbox.fs
Outdated
| type AsyncReplyChannel<'Reply>(replyf : 'Reply -> unit) = | ||
| member x.Reply value = replyf value | ||
|
|
||
| module private AsyncStarter = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think remove this module, and inline each of its elements. They don't make code any clearer, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I adapted Start method unit test for the new StartImmediate method, although I'm not certain I did it correctly. For example, this line "c32398u6: MailboxProcessor null" - I just copied it. Should the referenced id (c32398u6) be unique for each test?
I see that the new unit test fails on Windows CI machine because it doesn't see the new StartImmediate method, but it succeeds in other environments including my local Windows machine. I am not very familiar with the FSharp.Core test organization and appreciate help with this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need more testing, please add something that checks that a StartImmediate really happened
- remove AsyncStarter module - add unit test
dsyme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, the code looks good.
We need more testing, as noted
| check | ||
| "c32398u6: MailboxProcessor null" | ||
| (let mb1 = new MailboxProcessor<int>(fun inbox -> async { return () }) | ||
| mb1.StartImmediate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need more testing than this - create a MailboxProcessor that does a side effect during it's start?
|
Hey @xloggr, would you like to continue on that? |
|
@psfinaki Yes, please feel free to take over this work. It's a fairly simple addition but useful |
Hi @psfinaki, You are welcome to take over. |
|
Alright, I hope to get to this during this week. |
|
I would love to see this implemented and have a direct use case for it right now. So if anyone wants any help, I am happy to help out where I can. I made a comment in the issue (fsharp/fslang-suggestions#997). As I understand it, having a |
|
Hi @bmitc :) Thanks for chiming in! I think your assumption is correct. I don't have much expertise with this particular area of code, so if you have a direct use case and motivation - feel free to finish this one off, this is an excellent issue to "warm up" and I haven't started on this yet. You can fix this branch or open another PR, whatever you wish. |
|
I went ahead and created my own fork and branch to work on this. However, I have a question to help clarify how all this works. I recently asked this on Stack Overflow, and the same question applies here. Inside the async { try
do! body x
with exn ->
errorEvent.Trigger exn }It is the outer
|
|
I did an experiment that seems to imply that // async.fsx
let outerAsync = async {
printfn "Outer async thread: %A" System.Threading.Thread.CurrentThread.Name
do! async {
printfn "Inner async thread: %A" System.Threading.Thread.CurrentThread.Name
}
}
System.Threading.Thread.CurrentThread.Name <- "main thread"
printfn "Main thread: %A" System.Threading.Thread.CurrentThread.Name
printfn "Async.StartImmediate"
Async.StartImmediate outerAsync
printfn "Async.Start"
Async.Start outerAsyncThen running this: PS > dotnet fsi .\async.fsx
Main thread: "main thread"
Async.StartImmediate
Outer async thread: "main thread"
Inner async thread: "main thread"
Async.Start
Outer async thread: ".NET ThreadPool Worker"
Inner async thread: ".NET ThreadPool Worker" |
|
@bmitc great job drilling into that, admittedly printing the thread names in code is currently probably a much easier way to understand what's going on than digging into the code or the docs. I probably wouldn't give a better answer than the guy on the StackOverflow already did, in that
That said, it's definitely not where we want to be with our docs, so absolutely feel free to clarify this tutorial, either within or - even better - parallel to the changes in the MailboxProcessor. We, maintainers, can think that we write things clearly, but after all it's our customers for whom it should make sense :) |
|
Just a note that I have resumed working on this and hope to have a new PR up soon. |
|
@dsyme I'm working on this in another PR from my own branch, and am starting to add tests. Above, you requested that tests be added to What is the difference between that location and I've never added a test to F# before, and so I don't know the difference between these two locations in terms of preference or if one is for certain types of tests or another reason. My initial thought would have been to add tests to |
We are trying to migrate away from the former test suite, so, plese don't add anything new there unless necessary, add tests either to FSharp.Core.UnitTests (which, are, well, unit-test style tests for the core library), or to the |
|
Thank you @vzarytovskii! I will add to |
|
@bmitc thanks - sounds like a plan. |
|
@xloggr are you still planning to finish this? |
|
@bmitc are you still planning to finish this? :) |
|
I have been meaning to get back to this, as it stares me in the face in my PRs list. 😆 I believe where I left off was adding testing, as the change is not that complex. Let me get back it this week, as I think all I need to do is add some tests, and I can post a link to my PR here. |
|
I have updated my PR #14931 by updating my F# fork, rebasing on top of that, and adding a test, with some various other changes. CI is passing, but I have left a self-review with some questions. I think it will be good to move discussion there. |
|
Alright, I am closing this one then, thanks! |
No description provided.