-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyQueue.cs
More file actions
751 lines (662 loc) · 25.8 KB
/
Copy pathDependencyQueue.cs
File metadata and controls
751 lines (662 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
// Copyright Subatomix Research Inc.
// SPDX-License-Identifier: MIT
namespace DependencyQueue;
/// <summary>
/// A thread-safe generic queue that dequeues elements in dependency order.
/// </summary>
/// <typeparam name="T">
/// The type of objects stored in queue items.
/// </typeparam>
/// <seealso href="https://github.com/sharpjs/DependencyQueue"/>
/// <seealso href="https://en.wikipedia.org/wiki/Dependency_graph"/>
public class DependencyQueue<T> : IDisposable
{
// Items that are ready to dequeue
private readonly PredicateQueue<DependencyQueueItem<T>> _ready;
// Topics keyed by name
private readonly Dictionary<string, DependencyQueueTopic<T>> _topics;
// Comparer for topic names
private readonly StringComparer _comparer;
// Thing that an execution context must lock exclusively to access queue state
private readonly AsyncMonitor _monitor;
// Count of items in the queue
private int _count;
// Whether the dependency graph is valid, invalid, or of unknown validity
private Validity _validity;
// Possible values of _validity
private enum Validity { Unknown = 0, Invalid = -1, Valid = +1 }
/// <summary>
/// Initializes a new <see cref="DependencyQueue{T}"/> instance,
/// optionally with the specified topic name comparer.
/// </summary>
/// <param name="comparer">
/// The comparer to use to for topic names. If
/// <paramref name="comparer"/> is <see langword="null"/>, the queue
/// will compare topic names using case-sensitive ordinal comparison.
/// See <see cref="StringComparer"/> for typical comparers.
/// </param>
public DependencyQueue(StringComparer? comparer = null)
{
_ready = new();
_topics = new(_comparer = comparer ?? StringComparer.Ordinal);
_monitor = new();
_validity = Validity.Valid;
}
/// <summary>
/// Gets the collection of items that are ready to dequeue.
/// </summary>
internal PredicateQueue<DependencyQueueItem<T>> ReadyItems => _ready;
/// <summary>
/// Gets the dictionary that maps topic names to topics.
/// </summary>
internal Dictionary<string, DependencyQueueTopic<T>> Topics => _topics;
/// <summary>
/// Gets the comparer for topic names.
/// </summary>
public StringComparer Comparer => _comparer;
/// <summary>
/// Gets the count of items in the queue.
/// </summary>
public int Count => _count;
/// <summary>
/// Creates a builder that can create and enqueue items in the queue
/// incrementally.
/// </summary>
/// <returns>
/// A builder that can create and enqueue items in the queue
/// incrementally.
/// </returns>
/// <remarks>
/// ⚠ <strong>Warning:</strong>
/// This method is thread-safe, but the builder this method returns is
/// <b>not</b> thread-safe. To enqueue items incrementally in parallel,
/// use one builder per thread.
/// </remarks>
public DependencyQueueBuilder<T> CreateBuilder()
=> new(this);
/// <summary>
/// Adds an item containing the specified object to the queue.
/// </summary>
/// <param name="name">
/// The name to associate with the queue item. Cannot be
/// <see langword="null"/> or empty.
/// </param>
/// <param name="value">
/// The object to store in the queue item.
/// </param>
/// <param name="provides">
/// An optional collection of names of the topics that the queue item
/// provides in addition to the specified <paramref name="name"/>. A
/// name cannot be <see langword="null"/> or empty.
/// </param>
/// <param name="requires">
/// An optional collection of names of the topics that the queue item
/// requires. A name cannot be <see langword="null"/> or empty.
/// </param>
/// <returns>
/// The item that was added to the queue.
/// </returns>
/// <remarks>
/// This method is thread-safe.
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <paramref name="name"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="name"/> is an empty string, or
/// <paramref name="requires"/> and/or <paramref name="provides"/>
/// contains a <see langword="null"/> or an empty string.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public DependencyQueueItem<T> Enqueue(
string name,
T value,
IEnumerable<string>? provides = null,
IEnumerable<string>? requires = null)
{
var item = new DependencyQueueItem<T>(name, value, Comparer);
if (provides is not null)
{
RequireValidNames(provides, nameof(provides));
item.AddProvides(provides);
}
if (requires is not null)
{
RequireValidNames(requires, nameof(requires));
item.AddRequires(requires);
}
Enqueue(item);
return item;
}
private static void RequireValidNames(IEnumerable<string> names, string parameterName)
{
foreach (var name in names)
{
if (name is null)
throw Errors.ArgumentContainsNull(parameterName);
if (name.Length is 0)
throw Errors.ArgumentContainsEmpty(parameterName);
}
}
// Called by Enqueue and by DependencyQueueBuilder
internal void Enqueue(DependencyQueueItem<T> item)
{
if (item is null)
throw Errors.ArgumentNull(nameof(item));
using var @lock = _monitor.Acquire();
foreach (var name in item.Provides)
GetOrAddTopic(name).ProvidedBy.Add(item);
foreach (var name in item.Requires)
GetOrAddTopic(name).RequiredBy.Add(item);
if (item.Requires.Count == 0)
_ready.Enqueue(item);
_count++;
_validity = Validity.Unknown;
_monitor.PulseAll();
}
/// <summary>
/// Dequeues an item from the queue.
/// </summary>
/// <param name="predicate">
/// An optional delegate that receives an item's
/// <see cref="DependencyQueueItem{T}.Value"/> and returns
/// <see langword="true"/> to dequeue the item or
/// <see langword="false"/> otherwise. The method may invoke the
/// delegate multiple times.
/// </param>
/// <returns>
/// An item from the queue, or <see langword="null"/> if no more items
/// remain.
/// </returns>
/// <remarks>
/// <para>
/// If the queue is invalid, this method throws
/// <see cref="InvalidDependencyQueueException"/>. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </para>
/// <para>
/// This method returns only when an item is dequeued from the queue
/// or when no more items remain to dequeue.
/// </para>
/// <para>
/// If a non-<see langword="null"/> <paramref name="predicate"/> is
/// provided, this method tests each ready-to-dequeue item's
/// <see cref="DependencyQueueItem{T}.Value"/> and dequeues the first
/// item for which the predicate returns <see langword="true"/>. If
/// the predicate does not accept any ready item, then this method
/// blocks. While blocking, this method retests all ready items
/// against the predicate when either another item becomes ready to
/// dequeue or one second has elapsed since the previous test.
/// </para>
/// <para>
/// A dequeued item is not yet complete, and any depending items are
/// not yet ready to dequeue. Invoke <see cref="Complete"/> to mark a
/// dequeued item as complete and enable any depending items to be
/// dequeued.
/// </para>
/// <para>
/// This method is thread-safe.
/// </para>
/// </remarks>
/// <exception cref="InvalidDependencyQueueException">
/// The dependency graph is invalid. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public DependencyQueueItem<T>? Dequeue(Func<T, bool>? predicate = null)
{
const int OneSecond = 1000; // ms
predicate ??= AcceptAny;
using var @lock = _monitor.Acquire();
RequireValid();
for (;;)
{
// Check if all topics (and thus all items) are completed
if (_topics.Count is 0)
return null;
// Check if the ready queue has an item to dequeue that the caller accepts
if (_ready.TryDequeue(GetValue, predicate, out var item))
{
_count--;
return item;
}
// Some items are in progress, and either there are no more ready
// items, or the predicate rejected all of them. Wait for any
// in-progress items to complete and unblock some ready items, or
// for one second to elapse, after which the predicate might change
// its mind.
@lock.ReleaseUntilPulse(OneSecond);
}
}
/// <summary>
/// Dequeues an item from the queue asynchronously.
/// </summary>
/// <param name="cancellation">
/// The token to monitor for cancellation requests.
/// </param>
/// <returns>
/// A task that represents the asynchronous dequeue operation. When the
/// task completes, its <see cref="Task{T}.Result"/> is an item from the
/// queue, or <see langword="null"/> if no more items remain.
/// </returns>
/// <remarks>
/// <para>
/// If the queue is invalid, this method throws
/// <see cref="InvalidDependencyQueueException"/>. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </para>
/// <para>
/// This method returns only when an item is dequeued from the queue
/// or when no more items remain to dequeue.
/// </para>
/// <para>
/// A dequeued item is not yet complete, and any depending items are
/// not yet ready to dequeue. Invoke <see cref="Complete"/> to mark a
/// dequeued item as complete and enable any depending items to be
/// dequeued.
/// </para>
/// <para>
/// This method is thread-safe.
/// </para>
/// </remarks>
/// <exception cref="InvalidDependencyQueueException">
/// The dependency graph is invalid. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public Task<DependencyQueueItem<T>?> DequeueAsync(CancellationToken cancellation = default)
{
return DequeueAsync(null, cancellation);
}
/// <summary>
/// Dequeues an item from the queue asynchronously.
/// </summary>
/// <param name="predicate">
/// An optional delegate that receives an item's
/// <see cref="DependencyQueueItem{T}.Value"/> and returns
/// <see langword="true"/> to dequeue the item or
/// <see langword="false"/> otherwise. The method may invoke the
/// delegate multiple times.
/// </param>
/// <param name="cancellation">
/// The token to monitor for cancellation requests.
/// </param>
/// <returns>
/// A task that represents the asynchronous dequeue operation. When the
/// task completes, its <see cref="Task{T}.Result"/> is an item from the
/// queue, or <see langword="null"/> if no more items remain.
/// </returns>
/// <remarks>
/// <para>
/// If the queue is invalid, this method throws
/// <see cref="InvalidDependencyQueueException"/>. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </para>
/// <para>
/// This method returns only when an item is dequeued from the queue
/// or when no more items remain to dequeue.
/// </para>
/// <para>
/// If a non-<see langword="null"/> <paramref name="predicate"/> is
/// provided, this method tests each ready-to-dequeue item's
/// <see cref="DependencyQueueItem{T}.Value"/> and dequeues the first
/// item for which the predicate returns <see langword="true"/>. If
/// the predicate does not accept any ready item, then this method
/// delays. While delaying, this method retests all ready items
/// against the predicate when either another item becomes ready to
/// dequeue or one second has elapsed since the previous test.
/// </para>
/// <para>
/// A dequeued item is not yet complete, and any depending items are
/// not yet ready to dequeue. Invoke <see cref="Complete"/> to mark a
/// dequeued item as complete and enable any depending items to be
/// dequeued.
/// </para>
/// <para>
/// This method is thread-safe.
/// </para>
/// </remarks>
/// <exception cref="InvalidDependencyQueueException">
/// The dependency graph is invalid. The
/// <see cref="InvalidDependencyQueueException.Errors"/> collection
/// contains the errors that cause the queue to be invalid.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public async Task<DependencyQueueItem<T>?> DequeueAsync(
Func<T, bool>? predicate,
CancellationToken cancellation = default)
{
const int OneSecond = 1000; // ms
predicate ??= AcceptAny;
using var @lock = await _monitor.AcquireAsync(cancellation);
RequireValid();
for (;;)
{
// Check if all topics (and thus all items) are completed
if (_topics.Count is 0)
return null;
// Check if the ready queue has an item to dequeue that the caller accepts
if (_ready.TryDequeue(GetValue, predicate, out var item))
{
_count--;
return item;
}
// Some items are in progress, and either there are no more ready
// items, or the predicate rejected all of them. Wait for any
// in-progress items to complete and unblock some ready items, or
// for one second to elapse, after which the predicate might change
// its mind.
await @lock.ReleaseUntilPulseAsync(OneSecond, cancellation);
}
}
/// <summary>
/// Marks the specified item as complete.
/// </summary>
/// <param name="item">
/// The item to mark as complete.
/// </param>
/// <remarks>
/// <para>
/// If <paramref name="item"/> completes a topic, any items that depend
/// solely upon that topic become ready to dequeue.
/// </para>
/// <para>
/// This method is thread-safe.
/// </para>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <paramref name="item"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public void Complete(DependencyQueueItem<T> item)
{
if (item is null)
throw Errors.ArgumentNull(nameof(item));
using var @lock = _monitor.Acquire();
// A dequeued item will have no requirements, a precondition of being
// ready to dequeue. However, code might call Complete() on an item
// that was never dequeued ... or even ever enqueued in this queue.
// This method must handle all those cases.
foreach (var name in item.Requires)
{
// Check if topic exists
if (!_topics.TryGetValue(name, out var topic))
continue; // completed or never existed
// Mark this item as done
topic.RequiredBy.Remove(item);
// Check if topic needs to exist
if (topic.ProvidedBy.Count is not 0 || topic.RequiredBy.Count is not 0)
continue; // provided or required by other items
// Topic is no longer needed; remove it
_topics.Remove(name);
}
foreach (var name in item.Provides)
{
// Check if topic exists
if (!_topics.TryGetValue(name, out var topic))
continue; // already or never existed
// Mark this item as done
topic.ProvidedBy.Remove(item);
// Check if all of topic's items are completed
if (topic.ProvidedBy.Count is not 0)
continue;
// All of topic's items are completed; mark topic itself as completed
_topics.Remove(name);
// Update dependents
foreach (var dependent in topic.RequiredBy)
{
// Mark requirement as met
dependent.RemoveRequires(name);
// Check if all dependent's requirements are met
if (dependent.Requires.Count != 0)
continue;
// All of dependent's requirements are met; it becomes ready
_ready.Enqueue(dependent);
}
}
// Previously, this method avoided awaking any waiting tasks if the
// queue still had in-progress topics and no new items became ready
// to dequeue. That optimization was incorrect because completion of
// an item here could cause a predicate to accept an item that it
// previously rejected. Because predicate logic is hidden, the only
// safe option is to wake waiting tasks after every item completion.
_monitor.PulseAll();
}
/// <summary>
/// Removes all items from the queue.
/// </summary>
/// <remarks>
/// This method is thread-safe.
/// </remarks>
public void Clear()
{
using var @lock = _monitor.Acquire();
_ready .Clear();
_topics.Clear();
_count = 0;
_validity = Validity.Valid;
_monitor.PulseAll();
}
// Gets or adds a topic of the specified name.
private DependencyQueueTopic<T> GetOrAddTopic(string name)
{
return _topics.TryGetValue(name, out var topic)
? topic
: _topics[name] = new DependencyQueueTopic<T>(name);
}
/// <summary>
/// Checks whether the queue is valid.
/// </summary>
/// <returns>
/// If the queue state is valid, an empty list; otherwise, a list of
/// errors that prevent the queue state from being valid.
/// </returns>
/// <remarks>
/// This method is thread-safe.
/// </remarks>
public IReadOnlyList<DependencyQueueError> Validate()
{
using var @lock = _monitor.Acquire();
return ValidateCore();
}
private void RequireValid()
{
if (_validity is Validity.Valid)
return;
var errors = ValidateCore();
if (errors.Count is 0)
return;
throw Errors.QueueInvalid(errors);
}
private IReadOnlyList<DependencyQueueError> ValidateCore()
{
var errors = new List<DependencyQueueError>();
var visited = new Dictionary<string, bool>(_topics.Count, _comparer);
// Ensure topics are visited in a deterministic order
var topics = _topics.Values.ToArray();
Array.Sort(topics, (a, b) => _comparer.Compare(a.Name, b.Name));
foreach (var topic in topics)
{
if (topic.ProvidedBy.Count == 0)
errors.Add(DependencyQueueError.UnprovidedTopic(topic));
else
DetectCycles(null, topic, visited, errors);
}
_validity = errors.Count is 0
? Validity.Valid
: Validity.Invalid;
return errors;
}
private void DetectCycles(
DependencyQueueItem<T>? requiringItem,
DependencyQueueTopic<T> topic,
Dictionary<string, bool> visited,
List<DependencyQueueError> errors)
{
if (!visited.TryGetValue(topic.Name, out var done))
{
visited[topic.Name] = false; // in progress
foreach (var item in topic.ProvidedBy)
foreach (var name in item.Requires)
DetectCycles(item, _topics[name], visited, errors);
visited[topic.Name] = true; // done
}
else if (!done)
{
// NULLS: This block executes only in recursive invocations of
// this method, which always provide a non-null requiringItem.
errors.Add(DependencyQueueError.Cycle(requiringItem!, topic));
}
}
/// <summary>
/// Releases resources used by the object.
/// </summary>
/// <remarks>
/// ⚠ <strong>Warning:</strong>
/// This method is not thread-safe.
/// </remarks>
public void Dispose()
{
Dispose(managed: true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases the unmanaged resources and, optionally, the managed
/// resources used by the object. Invoked by <see cref="Dispose()"/>.
/// Derived classes should override this method to extend disposal
/// behavior.
/// </summary>
/// <param name="managed">
/// <see langword="true"/>
/// to release both managed and unmanaged resources;
/// <see langword="false"/>
/// to release only unmanaged resources.
/// </param>
/// <remarks>
/// ⚠ <strong>Warning:</strong>
/// This method is not thread-safe.
/// </remarks>
protected virtual void Dispose(bool managed)
{
if (!managed)
return;
_monitor.Dispose();
}
/// <summary>
/// Blocks the current thread until it acquires an exclusive lock on the
/// queue, and returns a read-only view of the queue state. To release
/// the lock, dispose the view.
/// </summary>
/// <returns>
/// A read-only view over the exclusively-locked queue.
/// </returns>
/// <remarks>
/// This method and the object model it returns are thread-safe.
/// </remarks>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public View Inspect()
{
return new(this, _monitor.Acquire());
}
/// <summary>
/// Waits asynchronously to acquire an exclusive lock on the queue, and
/// returns a read-only view of the queue state. To release the lock,
/// dispose the view.
/// </summary>
/// <param name="cancellation">
/// The token to monitor for cancellation requests.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. When the task
/// completes, its <see cref="Task{T}.Result"/> is a read-only view over
/// the exclusively-locked queue.
/// </returns>
/// <remarks>
/// This method and the object model it returns are thread-safe.
/// </remarks>
/// <exception cref="ObjectDisposedException">
/// The queue has been disposed.
/// </exception>
public async Task<View> InspectAsync(CancellationToken cancellation = default)
{
return new(this, await _monitor.AcquireAsync(cancellation));
}
private static readonly Func<DependencyQueueItem<T>, T>
GetValue = e => e.Value;
private static readonly Func<T, bool>
AcceptAny = _ => true;
/// <summary>
/// A read-only view over an exclusively-locked
/// <see cref="DependencyQueue{T}"/>. The current execution context
/// holds the lock until this object is disposed.
/// </summary>
public readonly struct View : IDisposable
{
private readonly DependencyQueue<T> _queue;
private readonly AsyncMonitor.Lock _lock;
internal View(DependencyQueue<T> queue, AsyncMonitor.Lock @lock)
{
_queue = queue;
_lock = @lock;
}
/// <summary>
/// Gets the underlying queue.
/// </summary>
public DependencyQueue<T> Queue => _queue;
/// <inheritdoc cref="DependencyQueue{T}.Comparer"/>
public StringComparer Comparer => _queue.Comparer;
/// <inheritdoc cref="DependencyQueue{T}.Count"/>
public int Count => _queue.Count;
/// <inheritdoc cref="DependencyQueue{T}.ReadyItems"/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public DependencyQueueItemQueueView<T> ReadyItems
{
get
{
_lock.RequireNotDisposed();
return new(_queue.ReadyItems, _lock);
}
}
/// <inheritdoc cref="DependencyQueue{T}.Topics"/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public DependencyQueueTopicDictionaryView<T> Topics
{
get
{
_lock.RequireNotDisposed();
return new(_queue.Topics, _lock);
}
}
/// <inheritdoc cref="AsyncMonitor.Lock.Dispose"/>
internal void Dispose()
{
_lock.Dispose();
}
/// <inheritdoc cref="AsyncMonitor.Lock.Dispose"/>
void IDisposable.Dispose()
{
Dispose();
}
}
}