Flutter Engine
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 (std::function< bool(void)> closure)
 
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 11 of file dart_isolate_runner.cc.

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

◆ ~AutoIsolateShutdown()

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

Definition at line 15 of file dart_isolate_runner.cc.

References FML_CHECK, FML_LOG, IsValid(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

15  {
16  if (!IsValid()) {
17  return;
18  }
21  runner_, [isolate = std::move(isolate_), &latch]() {
22  if (!isolate->Shutdown()) {
23  FML_LOG(ERROR) << "Could not shutdown isolate.";
24  FML_CHECK(false);
25  }
26  latch.Signal();
27  });
28  latch.Wait();
29 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
#define FML_LOG(severity)
Definition: logging.h:65
#define FML_CHECK(condition)
Definition: logging.h:68

Member Function Documentation

◆ get()

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

Definition at line 33 of file dart_isolate_runner.h.

References FML_CHECK, and flutter::testing::RunDartCodeInIsolate().

33  {
34  FML_CHECK(isolate_);
35  return isolate_.get();
36  }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ IsValid()

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

Definition at line 29 of file dart_isolate_runner.h.

References function, and RunInIsolateScope().

Referenced by RunInIsolateScope(), and ~AutoIsolateShutdown().

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

◆ RunInIsolateScope()

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

Definition at line 31 of file dart_isolate_runner.cc.

References IsValid(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by IsValid().

32  {
33  if (!IsValid()) {
34  return false;
35  }
36 
37  bool result = false;
40  runner_, [this, &result, &latch, closure]() {
41  tonic::DartIsolateScope scope(isolate_->isolate());
42  tonic::DartApiScope api_scope;
43  if (closure) {
44  result = closure();
45  }
46  latch.Signal();
47  });
48  latch.Wait();
49  return true;
50 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
std::function< void()> closure
Definition: closure.h:14

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