From 5eb7024cd117cf3d460fa816e9c349d4684d9d55 Mon Sep 17 00:00:00 2001 From: neuecc Date: Mon, 19 Aug 2024 17:06:43 +0900 Subject: [PATCH] Add Subject.Dispose(bool callOnCompleted) --- src/R3/Subject.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/R3/Subject.cs b/src/R3/Subject.cs index fd021cbd..68e4c7e2 100644 --- a/src/R3/Subject.cs +++ b/src/R3/Subject.cs @@ -231,13 +231,19 @@ void ThrowIfDisposed() } public void Dispose() + { + Dispose(true); + } + + public void Dispose(bool callOnCompleted) { if (completeState.TrySetDisposed(out var alreadyCompleted)) { - if (!alreadyCompleted) + if (!alreadyCompleted && callOnCompleted) { var currentVersion = GetVersion(); var node = root; + Volatile.Write(ref root, null); while (node != null) { if (node.Version > currentVersion) break; @@ -245,6 +251,10 @@ public void Dispose() node = node.Next; } } + else + { + Volatile.Write(ref root, null); + } } }