pushdeer/ios/Prototype_version/Pods/PromiseKit/Sources/hang.m
2021-12-23 00:19:55 +08:00

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;
}