mirror of
https://github.com/easychen/pushdeer.git
synced 2024-09-09 22:48:11 +08:00
30 lines
835 B
Objective-C
30 lines
835 B
Objective-C
#import "AnyPromise.h"
|
|
#import "AnyPromise+Private.h"
|
|
@import CoreFoundation.CFRunLoop;
|
|
|
|
/**
|
|
Suspends the active thread waiting on the provided promise.
|
|
|
|
@return The value of the provided promise once resolved.
|
|
*/
|
|
id PMKHang(AnyPromise *promise) {
|
|
if (promise.pending) {
|
|
static CFRunLoopSourceContext context;
|
|
|
|
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
|
|
CFRunLoopSourceRef runLoopSource = CFRunLoopSourceCreate(NULL, 0, &context);
|
|
CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopDefaultMode);
|
|
|
|
promise.ensure(^{
|
|
CFRunLoopStop(runLoop);
|
|
});
|
|
while (promise.pending) {
|
|
CFRunLoopRun();
|
|
}
|
|
CFRunLoopRemoveSource(runLoop, runLoopSource, kCFRunLoopDefaultMode);
|
|
CFRelease(runLoopSource);
|
|
}
|
|
|
|
return promise.value;
|
|
}
|