scan method
Implementation
@override
Stream<BleScanResult> scan({Duration? timeout}) async* {
_scanListeners++;
_activeScan ??= _startScan();
try {
await _activeScan;
if (timeout == null) {
yield* _scanResults.stream;
} else {
yield* _scanResults.stream.timeout(
timeout,
onTimeout: (EventSink<BleScanResult> sink) => sink.close(),
);
}
} finally {
_scanListeners--;
if (_scanListeners == 0) {
_activeScan = null;
await _stopScan();
}
}
}