Permalink
Browse files

SwiftPM support

  • Loading branch information...
mxcl committed Aug 3, 2016
1 parent f4cda67 commit 513a50421061d5032f643c65755d76ce18a90875
Showing with 61 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +22 −0 Package.swift
  3. +5 −1 PromiseKit.podspec
  4. +17 −10 Sources/Error.swift
  5. +16 −0 Sources/SwiftPM.swift
View
@@ -2,3 +2,4 @@
*.xcscmblueprint
/Carthage
/Cartfile.resolved
/.build
View
@@ -0,0 +1,22 @@
import PackageDescription
let package = Package(
name: "PromiseKit",
exclude: [
"Sources/AnyPromise.swift",
"Sources/Promise+AnyPromise.swift",
"Sources/AnyPromise.m",
"Sources/dispatch_promise.m",
"Sources/GlobalState.m",
"Sources/hang.m",
"Sources/NSMethodSignatureForBlock.m",
"Sources/join.m",
"Sources/PMKCallVariadicBlock.m",
"Sources/when.m",
"Sources/after.m",
"Sources/AnyPromise+Private.h",
"Sources/AnyPromise.h",
"Sources/PromiseKit.h",
"Tests"
]
)
View
@@ -80,8 +80,12 @@ Pod::Spec.new do |s|
s.subspec 'CorePromise' do |ss|
hh = Dir['Sources/*.h'] - Dir['Sources/*+Private.h']
cc = Dir['Sources/*.swift'] - ['Sources/SwiftPM.swift']
cc << 'Sources/{after,AnyPromise,GlobalState,dispatch_promise,hang,join,PMKPromise,when}.m'
cc += hh
ss.source_files = 'Sources/*.{swift}', 'Sources/{after,AnyPromise,GlobalState,dispatch_promise,hang,join,PMKPromise,when}.m', *hh
ss.source_files = cc
ss.public_header_files = hh
ss.preserve_paths = 'Sources/AnyPromise+Private.h', 'Sources/PMKCallVariadicBlock.m', 'Sources/NSMethodSignatureForBlock.m'
ss.frameworks = 'Foundation'
View
@@ -70,6 +70,12 @@ public enum JSONError: Error {
//////////////////////////////////////////////////////////// Cancellation
public protocol CancellableError: Error {
var isCancelled: Bool { get }
}
#if !SWIFT_PACKAGE
private struct ErrorPair: Hashable {
let domain: String
let code: Int
@@ -105,29 +111,30 @@ extension NSError {
}
}
public protocol CancellableError: Error {
var isCancelled: Bool { get }
}
private var cancelledErrorIdentifiers = Set([
ErrorPair(PMKErrorDomain, PMKOperationCancelled),
ErrorPair(NSURLErrorDomain, NSURLErrorCancelled),
])
#endif
extension Error {
public var isCancelledError: Bool {
if let ce = self as? CancellableError {
return ce.isCancelled
} else {
#if SWIFT_PACKAGE
return false
#else
let ne = self as NSError
return cancelledErrorIdentifiers.contains(ErrorPair(ne.domain, ne.code))
#endif
}
}
}
////////////////////////////////////////// Predefined Cancellation Errors
private var cancelledErrorIdentifiers = Set([
ErrorPair(PMKErrorDomain, PMKOperationCancelled),
ErrorPair(NSURLErrorDomain, NSURLErrorCancelled),
])
//////////////////////////////////////////////////////// Unhandled Errors
class ErrorConsumptionToken {
var consumed = false
View
@@ -0,0 +1,16 @@
public enum CatchPolicy {
case allErrorsExceptCancellation
case allErrors
}
func PMKUnhandledErrorHandler(_ error: Error)
{}
import class Dispatch.DispatchQueue
func __PMKDefaultDispatchQueue() -> DispatchQueue {
return DispatchQueue.main
}
func __PMKSetDefaultDispatchQueue(_: DispatchQueue)
{}

0 comments on commit 513a504

Please sign in to comment.