flutter_flutter/fml/platform/fuchsia/message_loop_fuchsia.cc
David Worsham e2aa235ab8
Fix most fml tests on Fuchsia (#14007)
* Add fuchsia MessageLoopImpl; fix several tests
2019-11-25 14:16:50 -08:00

39 lines
998 B
C++

// Copyright 2013 The Flutter 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/platform/fuchsia/message_loop_fuchsia.h"
#include <lib/async-loop/default.h>
#include <lib/async/cpp/task.h>
#include <lib/zx/time.h>
namespace fml {
MessageLoopFuchsia::MessageLoopFuchsia()
: loop_(&kAsyncLoopConfigAttachToCurrentThread) {}
MessageLoopFuchsia::~MessageLoopFuchsia() = default;
void MessageLoopFuchsia::Run() {
loop_.Run();
}
void MessageLoopFuchsia::Terminate() {
loop_.Quit();
}
void MessageLoopFuchsia::WakeUp(fml::TimePoint time_point) {
fml::TimePoint now = fml::TimePoint::Now();
zx::duration due_time{0};
if (time_point > now) {
due_time = zx::nsec((time_point - now).ToNanoseconds());
}
FML_DCHECK(async::PostDelayedTask(
loop_.dispatcher(), [this]() { RunExpiredTasksNow(); },
due_time) == ZX_OK);
}
} // namespace fml