Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::testing::AutoIsolateShutdown Class Reference

#include <dart_isolate_runner.h>

Public Member Functions

 AutoIsolateShutdown ()=default
 
 AutoIsolateShutdown (std::shared_ptr< DartIsolate > isolate, fml::RefPtr< fml::TaskRunner > runner)
 
 ~AutoIsolateShutdown ()
 
bool IsValid () const
 
bool RunInIsolateScope (const std::function< bool(void)> &closure)
 
void Shutdown ()
 
DartIsolateget ()
 

Detailed Description

Definition at line 20 of file dart_isolate_runner.h.

Constructor & Destructor Documentation

◆ AutoIsolateShutdown() [1/2]

flutter::testing::AutoIsolateShutdown::AutoIsolateShutdown ( )
default

◆ AutoIsolateShutdown() [2/2]

flutter::testing::AutoIsolateShutdown::AutoIsolateShutdown ( std::shared_ptr< DartIsolate isolate,
fml::RefPtr< fml::TaskRunner runner 
)

Definition at line 13 of file dart_isolate_runner.cc.

15 : isolate_(std::move(isolate)), runner_(std::move(runner)) {}

◆ ~AutoIsolateShutdown()

flutter::testing::AutoIsolateShutdown::~AutoIsolateShutdown ( )

Definition at line 17 of file dart_isolate_runner.cc.

17 {
18 if (!isolate_->IsShuttingDown()) {
19 Shutdown();
20 }
22 fml::TaskRunner::RunNowOrPostTask(runner_, [this, &latch]() {
23 // Delete isolate on thread.
24 isolate_.reset();
25 latch.Signal();
26 });
27 latch.Wait();
28}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
Definition: task_runner.cc:55

Member Function Documentation

◆ get()

DartIsolate * flutter::testing::AutoIsolateShutdown::get ( )
inline

Definition at line 36 of file dart_isolate_runner.h.

36 {
37 FML_CHECK(isolate_);
38 return isolate_.get();
39 }
#define FML_CHECK(condition)
Definition: logging.h:85

◆ IsValid()

bool flutter::testing::AutoIsolateShutdown::IsValid ( ) const
inline

Definition at line 29 of file dart_isolate_runner.h.

29{ return isolate_ != nullptr && runner_; }

◆ RunInIsolateScope()

bool flutter::testing::AutoIsolateShutdown::RunInIsolateScope ( const std::function< bool(void)> &  closure)

Definition at line 46 of file dart_isolate_runner.cc.

47 {
48 if (!IsValid()) {
49 return false;
50 }
51
52 bool result = false;
55 runner_, [this, &result, &latch, closure]() {
56 tonic::DartIsolateScope scope(isolate_->isolate());
57 tonic::DartApiScope api_scope;
58 if (closure) {
59 result = closure();
60 }
61 latch.Signal();
62 });
63 latch.Wait();
64 return result;
65}
GAsyncResult * result
std::function< void()> closure
Definition: closure.h:14

◆ Shutdown()

void flutter::testing::AutoIsolateShutdown::Shutdown ( )

Definition at line 30 of file dart_isolate_runner.cc.

30 {
31 if (!IsValid()) {
32 return;
33 }
36 runner_, [isolate = isolate_.get(), &latch]() {
37 if (!isolate->Shutdown()) {
38 FML_LOG(ERROR) << "Could not shutdown isolate.";
39 FML_CHECK(false);
40 }
41 latch.Signal();
42 });
43 latch.Wait();
44}

The documentation for this class was generated from the following files: