Remove Timer::FireNow.

PiperOrigin-RevId: 811123106
This commit is contained in:
Francis Tsui
2025-09-24 18:44:41 -07:00
committed by Copybara-Service
parent eb3ae063f5
commit 72088b7fe2
15 changed files with 0 additions and 142 deletions
@@ -103,22 +103,4 @@
XCTAssertTrue(timer->Stop());
}
- (void)testFireNow {
XCTestExpectation* expectation = [self expectationWithDescription:@"Timer fired"];
auto timer = std::make_unique<nearby::apple::Timer>();
bool fired = false;
XCTAssertTrue(timer->Create(1000, 0, [&]() {
dispatch_async(dispatch_get_main_queue(), ^{
fired = true;
[expectation fulfill];
});
}));
XCTAssertTrue(timer->FireNow());
[self waitForExpectationsWithTimeout:1.0 handler:nil];
XCTAssertTrue(fired);
}
@end
@@ -37,8 +37,6 @@ class Timer : public api::Timer {
bool Stop() override ABSL_LOCKS_EXCLUDED(mutex_);
bool FireNow() override ABSL_LOCKS_EXCLUDED(mutex_);
private:
absl::Mutex mutex_;
absl::CondVar condvar_ ABSL_GUARDED_BY(mutex_);
@@ -106,32 +106,5 @@ bool Timer::Stop() {
return true;
}
bool Timer::FireNow() {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
absl::AnyInvocable<void()> callback_to_run;
{
absl::MutexLock lock(&mutex_);
// Don't fire if there's no callback or if a callback is already in progress.
if (!callback_ || callback_running_) {
return;
}
callback_running_ = true;
callback_to_run = std::move(callback_);
}
// Execute callback outside of the lock.
callback_to_run();
{
absl::MutexLock lock(&mutex_);
callback_ = std::move(callback_to_run);
callback_running_ = false;
condvar_.Signal(); // Notify Stop() if it's waiting.
}
});
return true;
}
} // namespace apple
} // namespace nearby