Files
NativeScript/packages/core/utils/mainthread-helper.ios.ts
2022-04-25 08:36:20 -07:00

20 lines
471 B
TypeScript

export function dispatchToMainThread(func: () => void) {
NSOperationQueue.mainQueue.addOperationWithBlock(func);
}
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();
}
};
}