forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_runner.cc
41 lines (30 loc) · 1.08 KB
/
task_runner.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/task_runner.h"
#include <utility>
#include "flutter/fml/message_loop.h"
#include "flutter/fml/message_loop_impl.h"
namespace fml {
TaskRunner::TaskRunner(fxl::RefPtr<MessageLoopImpl> loop)
: loop_(std::move(loop)) {
FXL_CHECK(loop_);
}
TaskRunner::~TaskRunner() = default;
void TaskRunner::PostTask(fxl::Closure task) {
loop_->PostTask(std::move(task), fxl::TimePoint::Now());
}
void TaskRunner::PostTaskForTime(fxl::Closure task,
fxl::TimePoint target_time) {
loop_->PostTask(std::move(task), target_time);
}
void TaskRunner::PostDelayedTask(fxl::Closure task, fxl::TimeDelta delay) {
loop_->PostTask(std::move(task), fxl::TimePoint::Now() + delay);
}
bool TaskRunner::RunsTasksOnCurrentThread() {
if (!fml::MessageLoop::IsInitializedForCurrentThread()) {
return false;
}
return MessageLoop::GetCurrent().GetLoopImpl() == loop_;
}
} // namespace fml