1717using System . Diagnostics ;
1818using System . Threading ;
1919using System . Threading . Tasks ;
20- using MongoDB . Driver . Core . Misc ;
2120
2221namespace MongoDB . Driver
2322{
@@ -26,26 +25,26 @@ internal sealed class OperationContext
2625 // TODO: this static field is temporary here and will be removed in a future PRs in scope of CSOT.
2726 public static readonly OperationContext NoTimeout = new ( System . Threading . Timeout . InfiniteTimeSpan , CancellationToken . None ) ;
2827
29- private readonly Stopwatch _stopwatch ;
30-
3128 public OperationContext ( TimeSpan timeout , CancellationToken cancellationToken )
3229 : this ( Stopwatch . StartNew ( ) , timeout , cancellationToken )
3330 {
3431 }
3532
3633 internal OperationContext ( Stopwatch stopwatch , TimeSpan timeout , CancellationToken cancellationToken )
3734 {
38- _stopwatch = stopwatch ;
35+ Stopwatch = stopwatch ;
3936 Timeout = timeout ;
4037 CancellationToken = cancellationToken ;
4138 }
4239
4340 public CancellationToken CancellationToken { get ; }
4441
45- public TimeSpan Elapsed => _stopwatch . Elapsed ;
42+ public TimeSpan Elapsed => Stopwatch . Elapsed ;
4643
4744 public TimeSpan Timeout { get ; }
4845
46+ public OperationContext ParentContext { get ; private init ; }
47+
4948 public TimeSpan RemainingTimeout
5049 {
5150 get
@@ -55,10 +54,12 @@ public TimeSpan RemainingTimeout
5554 return System . Threading . Timeout . InfiniteTimeSpan ;
5655 }
5756
58- return Timeout - _stopwatch . Elapsed ;
57+ return Timeout - Elapsed ;
5958 }
6059 }
6160
61+ private Stopwatch Stopwatch { get ; }
62+
6263 public bool IsTimedOut ( )
6364 {
6465 var remainingTimeout = RemainingTimeout ;
@@ -82,7 +83,10 @@ public OperationContext WithTimeout(TimeSpan timeout)
8283 timeout = remainingTimeout ;
8384 }
8485
85- return new OperationContext ( timeout , CancellationToken ) ;
86+ return new OperationContext ( timeout , CancellationToken )
87+ {
88+ ParentContext = this
89+ } ;
8690 }
8791
8892 public void WaitTask ( Task task )
0 commit comments