Files
nearby/cpp/platform_v2/api/scheduled_executor.h
T
Alexey Polyudov ae1c427b99 nearby: snapshot of cl/313536507
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I8936b527079074d5c3af5531b9245063767cc4a7
2020-05-28 00:03:22 -07:00

37 lines
1.2 KiB
C++

#ifndef PLATFORM_V2_API_SCHEDULED_EXECUTOR_H_
#define PLATFORM_V2_API_SCHEDULED_EXECUTOR_H_
#include <cstdint>
#include <functional>
#include <memory>
#include "platform_v2/api/cancelable.h"
#include "platform_v2/api/executor.h"
#include "platform_v2/base/runnable.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
namespace api {
// An Executor that can schedule commands to run after a given delay, or to
// execute periodically.
//
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html
class ScheduledExecutor : public Executor {
public:
~ScheduledExecutor() override = default;
// Cancelable is kept both in the executor context, and in the caller context.
// We want Cancelable to live until both caller and executor are done with it.
// Exclusive ownership model does not work for this case;
// using std:shared_ptr<> instead if std::unique_ptr<>.
virtual std::shared_ptr<Cancelable> Schedule(Runnable&& runnable,
absl::Duration duration) = 0;
};
} // namespace api
} // namespace nearby
} // namespace location
#endif // PLATFORM_V2_API_SCHEDULED_EXECUTOR_H_