Compare commits
1 Commits
fix-NSErro
...
nt/queuein
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3fbd490a4 |
606
PromiseKit.podspec.json
Normal file
606
PromiseKit.podspec.json
Normal file
@ -0,0 +1,606 @@
|
||||
{
|
||||
"name": "PromiseKit",
|
||||
"version": "6.13.1",
|
||||
"source": {
|
||||
"git": "https://github.com/mxcl/PromiseKit.git",
|
||||
"tag": "6.13.1",
|
||||
"submodules": true
|
||||
},
|
||||
"license": "MIT",
|
||||
"summary": "Promises for Swift & ObjC.",
|
||||
"homepage": "http://mxcl.dev/PromiseKit/",
|
||||
"description": "A thoughtful and complete implementation of promises for iOS, macOS, watchOS and tvOS with first-class support for both Objective-C and Swift.",
|
||||
"social_media_url": "https://twitter.com/mxcl",
|
||||
"authors": {
|
||||
"Max Howell": "mxcl@me.com"
|
||||
},
|
||||
"documentation_url": "http://mxcl.dev/PromiseKit/reference/v6/Classes/Promise.html",
|
||||
"default_subspecs": [
|
||||
"CorePromise",
|
||||
"UIKit",
|
||||
"Foundation"
|
||||
],
|
||||
"requires_arc": true,
|
||||
"swift_versions": [
|
||||
"3.1",
|
||||
"3.2",
|
||||
"3.3",
|
||||
"3.4",
|
||||
"4.0",
|
||||
"4.1",
|
||||
"4.2",
|
||||
"4.3",
|
||||
"4.4",
|
||||
"5.0",
|
||||
"5.1"
|
||||
],
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
},
|
||||
"pod_target_xcconfig": {
|
||||
"OTHER_SWIFT_FLAGS": "-DPMKCocoaPods"
|
||||
},
|
||||
"subspecs": [
|
||||
{
|
||||
"name": "Accounts",
|
||||
"osx": {
|
||||
"source_files": "Extensions/Accounts/Sources/*",
|
||||
"frameworks": "Accounts"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/Accounts/Sources/*",
|
||||
"frameworks": "Accounts"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Alamofire",
|
||||
"source_files": "Extensions/Alamofire/Sources/*",
|
||||
"dependencies": {
|
||||
"Alamofire": [
|
||||
"~> 4.0"
|
||||
],
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.11",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "AddressBook",
|
||||
"ios": {
|
||||
"source_files": "Extensions/AddressBook/Sources/*",
|
||||
"frameworks": "AddressBook"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "AssetsLibrary",
|
||||
"ios": {
|
||||
"source_files": "Extensions/AssetsLibrary/Sources/*",
|
||||
"frameworks": "AssetsLibrary"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "AVFoundation",
|
||||
"ios": {
|
||||
"source_files": "Extensions/AVFoundation/Sources/*",
|
||||
"frameworks": "AVFoundation"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Bolts",
|
||||
"source_files": "Extensions/Bolts/Sources/*",
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
],
|
||||
"Bolts": [
|
||||
"~> 1.9.0"
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CloudKit",
|
||||
"source_files": "Extensions/CloudKit/Sources/*",
|
||||
"frameworks": "CloudKit",
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "10.0",
|
||||
"osx": "10.12",
|
||||
"tvos": "10.0",
|
||||
"watchos": "3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CoreBluetooth",
|
||||
"tvos": {
|
||||
"source_files": "Extensions/CoreBluetooth/Sources/*",
|
||||
"frameworks": "CoreBluetooth"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/CoreBluetooth/Sources/*",
|
||||
"frameworks": "CoreBluetooth"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/CoreBluetooth/Sources/*",
|
||||
"frameworks": "CoreBluetooth"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CorePromise",
|
||||
"source_files": [
|
||||
"Sources/when.swift",
|
||||
"Sources/Guarantee.swift",
|
||||
"Sources/race.swift",
|
||||
"Sources/Error.swift",
|
||||
"Sources/after.swift",
|
||||
"Sources/Resolver.swift",
|
||||
"Sources/Deprecations.swift",
|
||||
"Sources/hang.swift",
|
||||
"Sources/Box.swift",
|
||||
"Sources/Catchable.swift",
|
||||
"Sources/LogEvent.swift",
|
||||
"Sources/Promise.swift",
|
||||
"Sources/AnyPromise.swift",
|
||||
"Sources/firstly.swift",
|
||||
"Sources/CustomStringConvertible.swift",
|
||||
"Sources/Thenable.swift",
|
||||
"Sources/Configuration.swift",
|
||||
"Sources/{after,AnyPromise,GlobalState,dispatch_promise,hang,join,PMKPromise,when,race}.m",
|
||||
"Sources/fwd.h",
|
||||
"Sources/AnyPromise.h",
|
||||
"Sources/PromiseKit.h"
|
||||
],
|
||||
"public_header_files": [
|
||||
"Sources/fwd.h",
|
||||
"Sources/AnyPromise.h",
|
||||
"Sources/PromiseKit.h"
|
||||
],
|
||||
"preserve_paths": [
|
||||
"Sources/AnyPromise+Private.h",
|
||||
"Sources/PMKCallVariadicBlock.m",
|
||||
"Sources/NSMethodSignatureForBlock.m"
|
||||
],
|
||||
"frameworks": "Foundation",
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CoreLocation",
|
||||
"source_files": "Extensions/CoreLocation/Sources/*",
|
||||
"watchos": {
|
||||
"source_files": "Extensions/CoreLocation/Sources/CLGeocoder*"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"frameworks": "CoreLocation",
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "3.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "EventKit",
|
||||
"watchos": {
|
||||
"source_files": "Extensions/EventKit/Sources/*",
|
||||
"frameworks": "EventKit"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/EventKit/Sources/*",
|
||||
"frameworks": "EventKit"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/EventKit/Sources/*",
|
||||
"frameworks": "EventKit"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Foundation",
|
||||
"source_files": [
|
||||
"Extensions/Foundation/Sources/NSURLSession+AnyPromise.h",
|
||||
"Extensions/Foundation/Sources/NSNotificationCenter+Promise.swift",
|
||||
"Extensions/Foundation/Sources/NSNotificationCenter+AnyPromise.m",
|
||||
"Extensions/Foundation/Sources/afterlife.swift",
|
||||
"Extensions/Foundation/Sources/NSTask+AnyPromise.h",
|
||||
"Extensions/Foundation/Sources/NSURLSession+Promise.swift",
|
||||
"Extensions/Foundation/Sources/NSURLSession+AnyPromise.m",
|
||||
"Extensions/Foundation/Sources/NSObject+Promise.swift",
|
||||
"Extensions/Foundation/Sources/NSNotificationCenter+AnyPromise.h",
|
||||
"Extensions/Foundation/Sources/PMKFoundation.h",
|
||||
"Extensions/Foundation/Sources/Process+Promise.swift",
|
||||
"Extensions/Foundation/Sources/NSTask+AnyPromise.m"
|
||||
],
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"frameworks": "Foundation",
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "HealthKit",
|
||||
"source_files": [
|
||||
"Extensions/HealthKit/Sources/HealthKit+Promise.swift"
|
||||
],
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"frameworks": "HealthKit",
|
||||
"platforms": {
|
||||
"ios": "9.0",
|
||||
"watchos": "2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "HomeKit",
|
||||
"source_files": [
|
||||
"Extensions/HomeKit/Sources/HMAcessoryBrowser+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/HMHome+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/HMEventTrigger+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/HMCharacteristic+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/HMTrigger+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/Utils.swift",
|
||||
"Extensions/HomeKit/Sources/HMHomeManager+Promise.swift",
|
||||
"Extensions/HomeKit/Sources/HMActionSet+Promise.swift"
|
||||
],
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"frameworks": "HomeKit",
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"watchos": "3.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MapKit",
|
||||
"tvos": {
|
||||
"source_files": "Extensions/MapKit/Sources/*",
|
||||
"frameworks": "MapKit"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/MapKit/Sources/*",
|
||||
"frameworks": "MapKit"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/MapKit/Sources/*",
|
||||
"frameworks": "MapKit"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MessageUI",
|
||||
"ios": {
|
||||
"source_files": "Extensions/MessagesUI/Sources/*",
|
||||
"frameworks": "MessageUI"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "OMGHTTPURLRQ",
|
||||
"source_files": "Extensions/OMGHTTPURLRQ/Sources/*",
|
||||
"dependencies": {
|
||||
"PromiseKit/Foundation": [
|
||||
|
||||
],
|
||||
"OMGHTTPURLRQ": [
|
||||
"~> 3.2"
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"watchos": "2.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Photos",
|
||||
"osx": {
|
||||
"source_files": "Extensions/Photos/Sources/*",
|
||||
"frameworks": "Photos"
|
||||
},
|
||||
"tvos": {
|
||||
"source_files": "Extensions/Photos/Sources/*",
|
||||
"frameworks": "Photos"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/Photos/Sources/*",
|
||||
"frameworks": "Photos"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.13",
|
||||
"tvos": "10.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "QuartzCore",
|
||||
"tvos": {
|
||||
"source_files": "Extensions/QuartzCore/Sources/*",
|
||||
"frameworks": "QuartzCore"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/QuartzCore/Sources/*",
|
||||
"frameworks": "QuartzCore"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/QuartzCore/Sources/*",
|
||||
"frameworks": "QuartzCore"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Social",
|
||||
"ios": {
|
||||
"source_files": "Extensions/Social/Sources/*",
|
||||
"frameworks": "Social"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": [
|
||||
"Extensions/Social/Sources/SLRequest+AnyPromise.m",
|
||||
"Extensions/Social/Sources/SLRequest+Promise.swift",
|
||||
"Extensions/Social/Sources/PMKSocial.h",
|
||||
"Extensions/Social/Sources/SLRequest+AnyPromise.h",
|
||||
"Extensions/Social/Sources/SLComposeViewController+Promise.swift"
|
||||
],
|
||||
"frameworks": "Social"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/Foundation": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "StoreKit",
|
||||
"tvos": {
|
||||
"source_files": "Extensions/StoreKit/Sources/*",
|
||||
"frameworks": "StoreKit"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/StoreKit/Sources/*",
|
||||
"frameworks": "StoreKit"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/StoreKit/Sources/*",
|
||||
"frameworks": "StoreKit"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SystemConfiguration",
|
||||
"tvos": {
|
||||
"source_files": "Extensions/SystemConfiguration/Sources/*",
|
||||
"frameworks": "SystemConfiguration"
|
||||
},
|
||||
"osx": {
|
||||
"source_files": "Extensions/SystemConfiguration/Sources/*",
|
||||
"frameworks": "SystemConfiguration"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/SystemConfiguration/Sources/*",
|
||||
"frameworks": "SystemConfiguration"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"osx": "10.10",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "UIKit",
|
||||
"tvos": {
|
||||
"source_files": [
|
||||
"Extensions/UIKit/Sources/UIViewController+AnyPromise.m",
|
||||
"Extensions/UIKit/Sources/PMKUIKit.h",
|
||||
"Extensions/UIKit/Sources/UIView+AnyPromise.h",
|
||||
"Extensions/UIKit/Sources/UIView+Promise.swift",
|
||||
"Extensions/UIKit/Sources/UIViewController+AnyPromise.h",
|
||||
"Extensions/UIKit/Sources/UIView+AnyPromise.m",
|
||||
"Extensions/UIKit/Sources/UIViewPropertyAnimator+Promise.swift"
|
||||
],
|
||||
"frameworks": "UIKit"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": [
|
||||
"Extensions/UIKit/Sources/UIViewController+AnyPromise.m",
|
||||
"Extensions/UIKit/Sources/PMKUIKit.h",
|
||||
"Extensions/UIKit/Sources/UIView+AnyPromise.h",
|
||||
"Extensions/UIKit/Sources/UIView+Promise.swift",
|
||||
"Extensions/UIKit/Sources/UIViewController+AnyPromise.h",
|
||||
"Extensions/UIKit/Sources/UIView+AnyPromise.m",
|
||||
"Extensions/UIKit/Sources/UIViewPropertyAnimator+Promise.swift"
|
||||
],
|
||||
"frameworks": "UIKit"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"tvos": "9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "UIImagePickerController",
|
||||
"ios": {
|
||||
"source_files": "Extensions/UIKit/Sources/UIImagePickerController+Promise.swift",
|
||||
"frameworks": "UIKit",
|
||||
"xcconfig": {
|
||||
"GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) PMKImagePickerController=1"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/UIKit": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "WatchConnectivity",
|
||||
"watchos": {
|
||||
"source_files": "Extensions/WatchConnectivity/Sources/*",
|
||||
"frameworks": "WatchConnectivity"
|
||||
},
|
||||
"ios": {
|
||||
"source_files": "Extensions/WatchConnectivity/Sources/*",
|
||||
"frameworks": "WatchConnectivity"
|
||||
},
|
||||
"dependencies": {
|
||||
"PromiseKit/CorePromise": [
|
||||
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0",
|
||||
"watchos": "2.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"swift_version": "5.1"
|
||||
}
|
||||
@ -9,6 +9,7 @@ import Foundation
|
||||
*/
|
||||
@objc(__AnyPromise) public class __AnyPromise: NSObject {
|
||||
fileprivate let box: Box<Any?>
|
||||
public var currentQueue: DispatchQueue?
|
||||
|
||||
@objc public init(resolver body: (@escaping (Any?) -> Void) -> Void) {
|
||||
box = EmptyBox<Any?>()
|
||||
@ -127,6 +128,10 @@ import Foundation
|
||||
}
|
||||
|
||||
extension AnyPromise: Thenable, CatchMixin {
|
||||
public var currentQueue: DispatchQueue? {
|
||||
get { d.currentQueue }
|
||||
set { d.currentQueue = newValue }
|
||||
}
|
||||
|
||||
/// - Returns: A new `AnyPromise` bound to a `Promise<Any>`.
|
||||
public convenience init<U: Thenable>(_ bridge: U) {
|
||||
|
||||
@ -29,7 +29,7 @@ public extension CatchMixin {
|
||||
guard policy == .allErrors || !error.isCancelled else {
|
||||
fallthrough
|
||||
}
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(error)
|
||||
finalizer.pending.resolve(())
|
||||
}
|
||||
@ -80,7 +80,7 @@ public extension CatchMixin {
|
||||
rp.box.seal(.fulfilled(value))
|
||||
case .rejected(let error):
|
||||
if policy == .allErrors || !error.isCancelled {
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
let rv = try body(error)
|
||||
guard rv !== rp else { throw PMKError.returnedSelf }
|
||||
@ -113,7 +113,7 @@ public extension CatchMixin {
|
||||
case .fulfilled(let value):
|
||||
rg.box.seal(value)
|
||||
case .rejected(let error):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(error).pipe(to: rg.box.seal)
|
||||
}
|
||||
}
|
||||
@ -141,7 +141,7 @@ public extension CatchMixin {
|
||||
func ensure(on: DispatchQueue? = conf.Q.return, flags: DispatchWorkItemFlags? = nil, _ body: @escaping () -> Void) -> Promise<T> {
|
||||
let rp = Promise<T>(.pending)
|
||||
pipe { result in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body()
|
||||
rp.box.seal(result)
|
||||
}
|
||||
@ -170,7 +170,7 @@ public extension CatchMixin {
|
||||
func ensureThen(on: DispatchQueue? = conf.Q.return, flags: DispatchWorkItemFlags? = nil, _ body: @escaping () -> Guarantee<Void>) -> Promise<T> {
|
||||
let rp = Promise<T>(.pending)
|
||||
pipe { result in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body().done {
|
||||
rp.box.seal(result)
|
||||
}
|
||||
@ -213,7 +213,7 @@ public extension CatchMixin where T == Void {
|
||||
case .fulfilled:
|
||||
rg.box.seal(())
|
||||
case .rejected(let error):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(error)
|
||||
rg.box.seal(())
|
||||
}
|
||||
@ -239,7 +239,7 @@ public extension CatchMixin where T == Void {
|
||||
rg.box.seal(.fulfilled(()))
|
||||
case .rejected(let error):
|
||||
if policy == .allErrors || !error.isCancelled {
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
rg.box.seal(.fulfilled(try body(error)))
|
||||
} catch {
|
||||
|
||||
@ -7,6 +7,7 @@ import Dispatch
|
||||
*/
|
||||
public final class Guarantee<T>: Thenable {
|
||||
let box: PromiseKit.Box<T>
|
||||
public var currentQueue: DispatchQueue?
|
||||
|
||||
fileprivate init(box: SealedBox<T>) {
|
||||
self.box = box
|
||||
@ -80,7 +81,7 @@ public extension Guarantee {
|
||||
func done(on: DispatchQueue? = conf.Q.return, flags: DispatchWorkItemFlags? = nil, _ body: @escaping(T) -> Void) -> Guarantee<Void> {
|
||||
let rg = Guarantee<Void>(.pending)
|
||||
pipe { (value: T) in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(value)
|
||||
rg.box.seal(())
|
||||
}
|
||||
@ -98,7 +99,7 @@ public extension Guarantee {
|
||||
func map<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ body: @escaping(T) -> U) -> Guarantee<U> {
|
||||
let rg = Guarantee<U>(.pending)
|
||||
pipe { value in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
rg.box.seal(body(value))
|
||||
}
|
||||
}
|
||||
@ -109,7 +110,7 @@ public extension Guarantee {
|
||||
func map<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath<T, U>) -> Guarantee<U> {
|
||||
let rg = Guarantee<U>(.pending)
|
||||
pipe { value in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
rg.box.seal(value[keyPath: keyPath])
|
||||
}
|
||||
}
|
||||
@ -121,7 +122,7 @@ public extension Guarantee {
|
||||
func then<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ body: @escaping(T) -> Guarantee<U>) -> Guarantee<U> {
|
||||
let rg = Guarantee<U>(.pending)
|
||||
pipe { value in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(value).pipe(to: rg.box.seal)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import Dispatch
|
||||
*/
|
||||
public final class Promise<T>: Thenable, CatchMixin {
|
||||
let box: Box<Result<T>>
|
||||
public var currentQueue: DispatchQueue?
|
||||
|
||||
fileprivate init(box: SealedBox<Result<T>>) {
|
||||
self.box = box
|
||||
|
||||
@ -10,6 +10,19 @@ public protocol Thenable: class {
|
||||
|
||||
/// The resolved result or nil if pending.
|
||||
var result: Result<T>? { get }
|
||||
|
||||
var currentQueue: DispatchQueue? { get set }
|
||||
}
|
||||
|
||||
extension Thenable {
|
||||
func asyncIfNecessary(on queue: DispatchQueue?, flags: DispatchWorkItemFlags?, body: @escaping () -> Void) {
|
||||
if currentQueue != queue {
|
||||
currentQueue = queue
|
||||
queue.async(flags: flags) { body() }
|
||||
} else {
|
||||
body()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Thenable {
|
||||
@ -35,7 +48,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
let rv = try body(value)
|
||||
guard rv !== rp else { throw PMKError.returnedSelf }
|
||||
@ -73,7 +86,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
rp.box.seal(.fulfilled(try transform(value)))
|
||||
} catch {
|
||||
@ -100,7 +113,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
rp.box.seal(.fulfilled(value[keyPath: keyPath]))
|
||||
}
|
||||
case .rejected(let error):
|
||||
@ -131,7 +144,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
if let rv = try transform(value) {
|
||||
rp.box.seal(.fulfilled(rv))
|
||||
@ -162,7 +175,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
if let rv = value[keyPath: keyPath] {
|
||||
rp.box.seal(.fulfilled(rv))
|
||||
@ -202,7 +215,7 @@ public extension Thenable {
|
||||
pipe {
|
||||
switch $0 {
|
||||
case .fulfilled(let value):
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
do {
|
||||
try body(value)
|
||||
rp.box.seal(.fulfilled(()))
|
||||
@ -258,7 +271,7 @@ public extension Thenable {
|
||||
func tap(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ body: @escaping(Result<T>) -> Void) -> Promise<T> {
|
||||
return Promise { seal in
|
||||
pipe { result in
|
||||
on.async(flags: flags) {
|
||||
self.asyncIfNecessary(on: on, flags: flags) {
|
||||
body(result)
|
||||
seal.resolve(result)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user