feat: added Utils.executeOnUIThread

This commit is contained in:
Nathan Walker
2022-04-25 08:36:20 -07:00
parent 74e42fcb8b
commit 36a55dac7f
7 changed files with 41 additions and 3 deletions

View File

@@ -5,3 +5,15 @@ export function dispatchToMainThread(func: () => void) {
export function isMainThread(): boolean {
return NSThread.isMainThread;
}
export function dispatchToUIThread(func: () => void) {
const runloop = CFRunLoopGetMain();
return function (func) {
if (runloop && func) {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, func);
CFRunLoopWakeUp(runloop);
} else if (func) {
func();
}
};
}