mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 15:16:12 -04:00
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
37 lines
1.2 KiB
C++
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_
|