Flutter macOS Embedder
FlutterRunLoop Class Reference

#import <FlutterRunLoop.h>

Inheritance diagram for FlutterRunLoop:

Instance Methods

(void) - performBlock:
 
(void) - performBlock:afterDelay:
 
(void) - pollFlutterMessagesOnce
 

Class Methods

(void) + ensureMainLoopInitialized
 
(FlutterRunLoop *) + mainRunLoop
 

Detailed Description

Interface for scheduling tasks on the run loop.

Main difference between using FlutterRunLoop to schedule tasks compared to dispatch_async or [NSRunLoop performBlock:] is that FlutterRunLoop schedules the task in both common run loop mode and a private run loop mode, which allows it to run in mode where it only processes Flutter messages ([FlutterRunLoop pollFlutterMessagesOnce]).

Definition at line 15 of file FlutterRunLoop.h.

Method Documentation

◆ ensureMainLoopInitialized

+ (void) ensureMainLoopInitialized

Ensures that the FlutterRunLoop for main thread is initialized. Only needs to be called once and must be called on the main thread.

Definition at line 31 of file FlutterRunLoop.mm.

111  {
112  FML_DCHECK(NSRunLoop.currentRunLoop == NSRunLoop.mainRunLoop);
113  if (mainLoop == nil) {
114  mainLoop = [[FlutterRunLoop alloc] init];
115  }
116 }

Referenced by FlutterDisplayLinkTest::SetUp(), and FlutterVSyncWaiterTest::SetUp().

◆ mainRunLoop

+ (FlutterRunLoop *) mainRunLoop

Returns the FlutterRunLoop for the main thread.

Definition at line 31 of file FlutterRunLoop.mm.

118  {
119  FML_DCHECK(mainLoop != nil);
120  return mainLoop;
121 }

Referenced by TEST().

◆ performBlock:

- (void) performBlock: (void(^)(void))  block

Schedules a block to be executed on the main thread.

Definition at line 31 of file FlutterRunLoop.mm.

107  :(void (^)(void))block {
108  [self performBlock:block afterDelay:0];
109 }

◆ performBlock:afterDelay:

- (void) performBlock: (void(^)(void))  block
afterDelay: (NSTimeInterval)  delay 

Schedules a block to be executed on the main thread after a delay.

Definition at line 31 of file FlutterRunLoop.mm.

95  :(void (^)(void))block afterDelay:(NSTimeInterval)delay {
96  @synchronized(self) {
97  _tasks.emplace_back(block, CFAbsoluteTimeGetCurrent() + delay);
98  if (delay > 0) {
99  [self rearmTimer];
100  } else {
101  CFRunLoopSourceSignal(_source);
102  CFRunLoopWakeUp(_runLoop);
103  }
104  }
105 }
std::vector< Task > _tasks
CFRunLoopSourceRef _source

◆ pollFlutterMessagesOnce

- (void) pollFlutterMessagesOnce

Executes single iteration of the run loop in the mode where only Flutter messages are processed.

Definition at line 31 of file FlutterRunLoop.mm.

123  {
124  CFRunLoopRunInMode(kFlutterRunLoopMode, 0.1, YES);
125 }

Referenced by TEST_F().


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