The MailboxProcessor class implements IDisposable but does not provide a Dispose method. To properly dispose of a MailboxProcessor, users need to cast such as this:
(mailboxProcessor :> IDisposable).Dispose()
I propose simply adding a Dispose method to MailboxProcessor.
Pros and Cons
The advantages of making this adjustment to F# are ...
-
Better discovery. There are two ways to create a MailbxoProcessor.
-
Directly using the constructor. For example,
// Binding with `use`, `Dispose` will be called automatically
use mailboxProcessor = new MailboxProcessor<unit>(fun inbox -> ...)
// Binding with `let`, users need to manually call `Dispose` by doing the above mentioned cast
let mailboxProcessor = new MailboxProcessor<unit>(fun inbox -> ...)
...
(mailboxProcessor :> IDisposable).Dispose()
Note that in these cases, F# will generate a warning if the new keyword is not used, which lets users know that MailboxProcessor implements IDisposable.
-
Using the Start method:
let mailboxProcessor = MailboxProcessor<Unit>.Start(fun inbox -> ...)
In this case, there is no indication that MailboxProcessor implements IDisposable since a static method is used to create and start it. Adding a Dispose method to the class would provide a discoverability aspect since the method will be listed by intellisense.
-
More convenience. I don't like having to manually cast objects every time I just want them disposed. MailboxProcessors are often created in situations where use can't be used, either when the MailboxProcessor<_>.Start method is used, or when a MailboxProcessor is created with a let binding in a class' constructor.
The disadvantages of making this adjustment to F# are ...
There are no downsides. This change would be completely backwards compatible with existing code since it only adds the following code to MailboxProcessor:
member x.Dispose () =
(x :> IDisposable).Dispose()
Extra information
Estimated cost (XS, S, M, L, XL, XXL): XS
Related suggestions: (put links to related suggestions here)
These are some related issues that address keeping the new keyword warning on constructors for IDisposable classes and asking how to dispose a MailboxProcessor.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
I could implement this with no problem.
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The
MailboxProcessorclass implementsIDisposablebut does not provide aDisposemethod. To properly dispose of aMailboxProcessor, users need to cast such as this:I propose simply adding a
Disposemethod toMailboxProcessor.Pros and Cons
The advantages of making this adjustment to F# are ...
Better discovery. There are two ways to create a
MailbxoProcessor.Directly using the constructor. For example,
Note that in these cases, F# will generate a warning if the
newkeyword is not used, which lets users know thatMailboxProcessorimplementsIDisposable.Using the
Startmethod:In this case, there is no indication that
MailboxProcessorimplementsIDisposablesince a static method is used to create and start it. Adding aDisposemethod to the class would provide a discoverability aspect since the method will be listed by intellisense.More convenience. I don't like having to manually cast objects every time I just want them disposed.
MailboxProcessors are often created in situations whereusecan't be used, either when theMailboxProcessor<_>.Startmethod is used, or when aMailboxProcessoris created with aletbinding in a class' constructor.The disadvantages of making this adjustment to F# are ...
There are no downsides. This change would be completely backwards compatible with existing code since it only adds the following code to
MailboxProcessor:Extra information
Estimated cost (XS, S, M, L, XL, XXL): XS
Related suggestions: (put links to related suggestions here)
These are some related issues that address keeping the
newkeyword warning on constructors forIDisposableclasses and asking how to dispose aMailboxProcessor.Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
I could implement this with no problem.
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.