Files
nearby/cpp/platform/api/scheduled_executor.h
T
Alexey Polyudov 2155b3ddeb Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
2020-10-22 10:47:34 -07:00

37 lines
1.2 KiB
C++

#ifndef PLATFORM_API_SCHEDULED_EXECUTOR_H_
#define PLATFORM_API_SCHEDULED_EXECUTOR_H_
#include <cstdint>
#include <functional>
#include <memory>
#include "platform/api/cancelable.h"
#include "platform/api/executor.h"
#include "platform/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_API_SCHEDULED_EXECUTOR_H_