Class EventDataCollector<T>
- Namespace
- WebDriverBiDi
- Assembly
- WebDriverBiDi.dll
Specialized observer of an event that collects event data each time the event is raised, for on-demand batch inspection or async streaming rather than immediate per-event reaction.
public sealed class EventDataCollector<T> : IDisposable, IAsyncDisposable where T : WebDriverBiDiEventArgs
Type Parameters
TThe type of event arguments containing information about the observable event.
- Inheritance
-
EventDataCollector<T>
- Implements
- Inherited Members
Examples
await using EventDataCollector<BeforeRequestSentEventArgs> collector =
driver.Network.OnBeforeRequestSent.AddDataCollector();
await driver.BrowsingContext.NavigateAsync(navParams);
IReadOnlyList<BeforeRequestSentEventArgs> requests = collector.GetCollectedEventData();
Console.WriteLine($"Page made {requests.Count} network requests");
Remarks
Use EventDataCollector<T> when you want to accumulate event data and examine it
at a convenient point in your code. Use GetCollectedEventData() to drain all events
that have accumulated since the last call; the internal buffer is cleared on each drain so
subsequent calls return only new events. Use Events to stream events one at a
time via await foreach; the sequence ends when the collector is disposed.
The collector counts as one observer against the event's
MaxObserverCount. Create it through
AddDataCollector(Func<T, bool>?, string) and dispose it (or await using it)
when collection is no longer needed to avoid memory leaks.
Thread Safety: All public members are thread-safe. GetCollectedEventData() and Events may be called concurrently with event notifications. Do not call GetCollectedEventData() concurrently with Events; use one reading approach at a time.
Properties
Events
Gets an IAsyncEnumerable<T> that yields each collected event as it arrives. The sequence ends when the collector is disposed.
public IAsyncEnumerable<T> Events { get; }
Property Value
Methods
Dispose()
Removes this data collector from its observable event and releases all resources.
public void Dispose()
DisposeAsync()
Asynchronously removes this data collector from its observable event and releases all resources.
public ValueTask DisposeAsync()
Returns
GetCollectedEventData()
Returns all event data accumulated since the last call and clears the internal buffer.
public IReadOnlyList<T> GetCollectedEventData()
Returns
- IReadOnlyList<T>
A read-only list of all
Tinstances collected since the previous call (or since the collector was created if this is the first call). Returns an empty list when no events occurred in that interval.
Exceptions
- ObjectDisposedException
Thrown when calling this method after the collector is disposed.
ToString()
Gets the string representation of this event data collector.
public override string ToString()
Returns
- string
The string representation of this event data collector.