mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove Timer::FireNow.
PiperOrigin-RevId: 811123106
This commit is contained in:
committed by
Copybara-Service
parent
eb3ae063f5
commit
72088b7fe2
@@ -22,7 +22,6 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/runnable.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
@@ -63,27 +62,5 @@ bool Timer::Stop() {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Timer::FireNow() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
if (!callback_) {
|
||||
LOG(ERROR) << "callback_ is empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (task_executor_ == nullptr) {
|
||||
task_executor_ = std::make_unique<SubmittableExecutor>();
|
||||
}
|
||||
|
||||
if (task_executor_ == nullptr) {
|
||||
LOG(ERROR) << "Failed to fire the task due to cannot create executor.";
|
||||
return false;
|
||||
}
|
||||
|
||||
task_executor_->Execute([&]() { callback_(); });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/cancelable.h"
|
||||
#include "internal/platform/implementation/timer.h"
|
||||
#include "internal/platform/implementation/windows/submittable_executor.h"
|
||||
#include "internal/platform/implementation/windows/task_scheduler.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -39,13 +38,10 @@ class Timer : public api::Timer {
|
||||
absl::AnyInvocable<void()> callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool Stop() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool FireNow() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
mutable absl::Mutex mutex_;
|
||||
absl::AnyInvocable<void()> callback_;
|
||||
std::unique_ptr<SubmittableExecutor> task_executor_ ABSL_GUARDED_BY(mutex_) =
|
||||
nullptr;
|
||||
TaskScheduler task_scheduler_ ABSL_GUARDED_BY(mutex_);
|
||||
std::shared_ptr<api::Cancelable> cancelable_task_ ABSL_GUARDED_BY(mutex_) =
|
||||
nullptr;
|
||||
|
||||
@@ -55,24 +55,6 @@ TEST(TimerTest, TestRepeatTimer) {
|
||||
EXPECT_TRUE(timer->Stop());
|
||||
}
|
||||
|
||||
TEST(TimerTest, TestFireNow) {
|
||||
int count = 0;
|
||||
absl::Notification notification;
|
||||
|
||||
auto timer = nearby::api::ImplementationPlatform::CreateTimer();
|
||||
|
||||
EXPECT_TRUE(timer != nullptr);
|
||||
EXPECT_TRUE(timer->Create(3000, 3000, [&count, ¬ification]() {
|
||||
++count;
|
||||
notification.Notify();
|
||||
}));
|
||||
EXPECT_TRUE(timer->FireNow());
|
||||
EXPECT_TRUE(timer->Stop());
|
||||
EXPECT_TRUE(
|
||||
notification.WaitForNotificationWithTimeout(absl::Milliseconds(1000)));
|
||||
EXPECT_EQ(count, 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user