Repository navigation
fix(js/ts/python): make MailboxProcessor disposable - #5364
Merged
MangelMaxime merged 7 commits intoDec 2, 2026
Merged
Conversation
MailboxProcessor implements IDisposable on .NET, but the class had no Dispose, so `use agent = ...` inside an async workflow failed with "resource.Dispose is not a function" and an explicit Dispose threw. Dispose does nothing, as on .NET, where it only releases a wait handle: the agent keeps running and keeps its messages.
Add the Dispose that .NET's IDisposable MailboxProcessor has, so `use` inside an async workflow and an explicit Dispose no longer fail with AttributeError. Like .NET, it neither stops the agent nor drops its messages.
MangelMaxime
force-pushed
the
support-mailbox-dispose
branch
from
December 2, 2026 08:02
f97f274 to
abd12d0
Compare
Member
|
Thank you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MailboxProcessor<'Msg>implementsIDisposableon .NET. On JS/TS and Python, the class has noDispose:use agent = MailboxProcessor.Start(...)inasyncfails at the end of the scope, withresource.Dispose is not a functionon JS andAttributeErroron Python.agent.Dispose()call.Disposenow does what FSharp.Core 11 does:PostorPostAndAsyncReplythat comes afterDispose. APostAndAsyncReplyafterDisposenever completes.isThrowExceptionAfterDisposed = true, a post afterDisposethrowsObjectDisposedException.Other changes:
isThrowExceptionAfterDisposedoverloads ofMailboxProcessorandMailboxProcessor.Startwork. Before, Fable gave theboolto the library as the cancellation token.ObjectDisposedExceptionon JS/TS and Python, with its 3 public constructors andObjectName.InvalidOperationExceptionhas a(message, innerException)constructor, becauseObjectDisposedExceptioninherits from it. On Python,InvalidOperationException.__init__now takes 2 arguments. This changes only hand-written Python code orEmitcode that calls it.MailboxProcessortests useAsync.RunSynchronously. Before, they usedAsync.StartImmediate, and the test ended before the assertions ran.Beam is not changed: its
MailboxProcessoris in Erlang. Dart and Rust do not supportMailboxProcessor.