Add PromiseKit dependency
- Added PromiseKit dependency
This commit is contained in:
29
Carthage/Checkouts/PromiseKit/Sources/hang.m
vendored
Normal file
29
Carthage/Checkouts/PromiseKit/Sources/hang.m
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user