mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
18 lines
435 B
TypeScript
18 lines
435 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();
|
|
if (runloop && func) {
|
|
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, func);
|
|
CFRunLoopWakeUp(runloop);
|
|
} else if (func) {
|
|
func();
|
|
}
|
|
}
|