Introduce scanning sessions

FastPairScanner::ScanningSession and ScannerBroker::ScanningSession separate
the lifetime of FastPairScanner/ScannerBroker from the lifetime of scanning
sessions. This simplifies the cleanup.
PiperOrigin-RevId: 535675988
This commit is contained in:
Janusz Sobczak
2023-05-26 11:50:54 -07:00
committed by Copybara-Service
parent 4596f32499
commit 3adb98a5ff
13 changed files with 122 additions and 24 deletions
@@ -34,6 +34,15 @@ class ABSL_LOCKABLE SingleThreadExecutor : public SubmittableExecutor {
SingleThreadExecutor& operator=(SingleThreadExecutor&&) = default;
};
// Moves the object to `executor` and destroys it there.
// This pattern is useful when there are some tasks running on `executor` that
// hold a reference to `object`. The tasks will complete before `object` is
// destroyed.
template <typename T>
void DestroyOnExecutor(T object, SingleThreadExecutor* executor) {
executor->Execute([object = std::move(object)] {});
}
} // namespace nearby
#endif // PLATFORM_PUBLIC_SINGLE_THREAD_EXECUTOR_H_