1616 protected_cont ,
1717)
1818from .option import erase , some
19- from .system import TimeoutException__ctor_Z721C83C5
19+ from .system import ObjectDisposedException__ctor_Z721C83C5 , TimeoutException__ctor_Z721C83C5
2020
2121
2222class AsyncReplyChannel [Reply ]:
@@ -32,6 +32,7 @@ def __init__(
3232 self ,
3333 body : Callable [[MailboxProcessor [Msg ]], Async [None ]],
3434 cancellation_token : CancellationToken | None = None ,
35+ is_throw_exception_after_disposed : bool = False ,
3536 ):
3637 self .messages : SimpleQueue [Msg ] = SimpleQueue ()
3738 self .token = cancellation_token or CancellationToken ()
@@ -41,6 +42,7 @@ def __init__(
4142 # Holds the continuation i.e the `done` callback of Async.from_continuations returned by `receive`.
4243 self .continuation : Continuations [Any ] | None = None
4344 self .is_disposed = False
45+ self .is_throw_exception_after_disposed = is_throw_exception_after_disposed
4446
4547 def post (self , msg : Msg ) -> None :
4648 """Post a message synchronously to the mailbox processor.
@@ -228,6 +230,8 @@ def __process_events(self) -> None:
228230 def __enqueue (self , msg : Msg ) -> None :
229231 with self .lock :
230232 if self .is_disposed :
233+ if self .is_throw_exception_after_disposed :
234+ raise ObjectDisposedException__ctor_Z721C83C5 ("Mailbox" )
231235 return
232236 self .messages .put (msg )
233237
@@ -242,8 +246,9 @@ def start(
242246 cls ,
243247 body : Callable [[MailboxProcessor [Msg ]], Async [None ]],
244248 cancellation_token : CancellationToken | None = None ,
249+ is_throw_exception_after_disposed : bool = False ,
245250 ) -> MailboxProcessor [Msg ]:
246- mbox : MailboxProcessor [Msg ] = MailboxProcessor (body , cancellation_token )
251+ mbox : MailboxProcessor [Msg ] = MailboxProcessor (body , cancellation_token , is_throw_exception_after_disposed )
247252 start_immediate (body (mbox ), mbox .token )
248253 return mbox
249254
@@ -274,8 +279,9 @@ def start_instance(mbox: MailboxProcessor[Any]) -> None:
274279def start [Msg ](
275280 body : Callable [[MailboxProcessor [Msg ]], Async [None ]],
276281 cancellationToken : CancellationToken | None = None ,
282+ is_throw_exception_after_disposed : bool = False ,
277283) -> MailboxProcessor [Msg ]:
278- mbox = MailboxProcessor (body , cancellationToken )
284+ mbox = MailboxProcessor (body , cancellationToken , is_throw_exception_after_disposed )
279285 start_instance (mbox )
280286 return mbox
281287
0 commit comments