1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef LIB_TONIC_DART_MICROTASK_QUEUE_H_
6#define LIB_TONIC_DART_MICROTASK_QUEUE_H_
7
8#include <vector>
9
10#include "third_party/dart/runtime/include/dart_api.h"
11#include "tonic/dart_persistent_value.h"
12#include "tonic/logging/dart_error.h"
13
14namespace tonic {
15
16class DartMicrotaskQueue {
17 public:
18 DartMicrotaskQueue();
19 ~DartMicrotaskQueue();
20
21 static void StartForCurrentThread();
22
23 static DartMicrotaskQueue* GetForCurrentThread();
24
25 void ScheduleMicrotask(Dart_Handle callback);
26 void RunMicrotasks();
27 void Destroy();
28
29 bool HasMicrotasks() const { return !queue_.empty(); }
30
31 DartErrorHandleType GetLastError();
32
33 private:
34 typedef std::vector<DartPersistentValue> MicrotaskQueue;
35
36 DartErrorHandleType last_error_;
37 MicrotaskQueue queue_;
38};
39
40} // namespace tonic
41
42#endif // LIB_TONIC_DART_MICROTASK_QUEUE_H_
43