blob: 28d8129610d24f935deaff541f7911ee93ed6658 [file] [log] [blame] [view]
# snapshot method
*[<Null safety>](https://dart.dev/null-safety)*
Future&lt;List&lt;[DiagnosticsData](../../package-fuchsia_inspect_reader/DiagnosticsData-class.md)&lt;METADATA>>> snapshot
({bool acceptSnapshot(List&lt;[DiagnosticsData](../../package-fuchsia_inspect_reader/DiagnosticsData-class.md)&lt;METADATA>> snapshot)?, Duration attemptDelay = const Duration(milliseconds: 100), int? maxAttempts = 200})
<p>Obtain a snapshot of the current inspect data as constrained by
<code>selector</code>.</p>
<p>The return value is the json object returned by <code>FormattedContent.json</code> as
parsed by <code>jsonDecode</code>.</p>
<p>If <code>acceptSnapshot</code> is not null, this method returns a snapshot once
<code>acceptSnapshot</code> returns true. If <code>maxAttempts</code> is not null, at most
<code>maxAttempts</code> are made to obtain a snapshot. <code>delay</code> controls the delay
between snapshot attempts.</p>
## Implementation
```dart
Future<List<DiagnosticsData<METADATA>>> snapshot(
{bool acceptSnapshot(List<DiagnosticsData<METADATA>> snapshot)?,
Duration attemptDelay = const Duration(milliseconds: 100),
int? maxAttempts = 200}) async {
for (var attempts = 0;
maxAttempts == null || attempts < maxAttempts;
attempts++) {
final snapshot = await _snapshotAttempt;
if (acceptSnapshot == null || acceptSnapshot(snapshot)) {
return snapshot;
}
await Future.delayed(attemptDelay);
}
throw Exception('snapshot failed');
}
```