Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'possen-swift4.0beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomvis committed Jul 23, 2017
2 parents f18744a + 17a4479 commit 7e08010
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8
osx_image: xcode9

script:
- xcodebuild test -workspace BrightFutures.xcworkspace -scheme BrightFutures-Mac
Expand Down
4 changes: 2 additions & 2 deletions BrightFutures.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BrightFutures'
s.version = '5.2.0'
s.version = '6.0.0-beta.1'
s.license = 'MIT'
s.summary = 'Write great asynchronous code in Swift using futures and promises'
s.homepage = 'https://github.com/Thomvis/BrightFutures'
Expand All @@ -19,5 +19,5 @@ Pod::Spec.new do |s|

s.requires_arc = true

s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
end
95 changes: 56 additions & 39 deletions BrightFutures.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" "3.2.1"
github "antitypical/Result" "3.2.3"
7 changes: 5 additions & 2 deletions Sources/BrightFutures/AsyncType+Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public extension LoggerType {
}
}

fileprivate struct Logger: LoggerType {
func log(message: String) {
public struct Logger: LoggerType {
public init() {
}

public func log(message: String) {
print(message)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/BrightFutures/AsyncType+ResultType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public extension AsyncType where Value: ResultProtocol {
/// This function should be used in cases where there are two asynchronous operations where the second operation (returned from the given closure)
/// should only be executed if the first (this future) fails.
/// The closure is executed on the given context. If no context is given, the behavior is defined by the default threading model (see README.md)
public func recoverWith<E1: Error>(context c: @escaping ExecutionContext = DefaultThreadingModel(), task: @escaping (Value.Error) -> Future<Value.Value, E1>) -> Future<Value.Value, E1> {
public func recoverWith<E1>(context c: @escaping ExecutionContext = DefaultThreadingModel(), task: @escaping (Value.Error) -> Future<Value.Value, E1>) -> Future<Value.Value, E1> {
let res = Future<Value.Value, E1>()

self.onComplete(c) { result in
Expand All @@ -131,14 +131,14 @@ public extension AsyncType where Value: ResultProtocol {

/// See `mapError<E1>(context c: ExecutionContext, f: E -> E1) -> Future<T, E1>`
/// The given closure is executed according to the default threading model (see README.md)
public func mapError<E1: Error>(_ f: @escaping (Value.Error) -> E1) -> Future<Value.Value, E1> {
public func mapError<E1>(_ f: @escaping (Value.Error) -> E1) -> Future<Value.Value, E1> {
return mapError(DefaultThreadingModel(), f: f)
}

/// Returns a future that fails with the error returned from the given closure when it is invoked with the error
/// from this future. If this future succeeds, the returned future succeeds with the same value and the closure is not executed.
/// The closure is executed on the given context.
public func mapError<E1: Error>(_ context: @escaping ExecutionContext, f: @escaping (Value.Error) -> E1) -> Future<Value.Value, E1> {
public func mapError<E1>(_ context: @escaping ExecutionContext, f: @escaping (Value.Error) -> E1) -> Future<Value.Value, E1> {
let res = Future<Value.Value, E1>()

self.onComplete(context) { result in
Expand Down Expand Up @@ -216,7 +216,7 @@ public extension AsyncType where Value: ResultProtocol, Value.Error == NoError {
/// This allows the `Future` to be used more easily in combination with other futures
/// for operations such as `sequence` and `firstCompleted`
/// This is a safe operation, because a `Future` with error type `NoError` is guaranteed never to fail
public func promoteError<E: Error>() -> Future<Value.Value, E> {
public func promoteError<E>() -> Future<Value.Value, E> {
return mapError(ImmediateExecutionContext) { $0 as! E } // future will never fail, so this map block will never get called
}
}
Expand All @@ -227,7 +227,7 @@ public extension AsyncType where Value: ResultProtocol, Value.Error == BrightFut
/// This allows the `Future` to be used more easily in combination with other futures
/// for operations such as `sequence` and `firstCompleted`
/// This is a safe operation, because a `BrightFuturesError<NoError>` will never be `.External`
public func promoteError<E: Error>() -> Future<Value.Value, BrightFuturesError<E>> {
public func promoteError<E>() -> Future<Value.Value, BrightFuturesError<E>> {
return mapError(ImmediateExecutionContext) { err in
switch err {
case .noSuchElement:
Expand Down
2 changes: 1 addition & 1 deletion Sources/BrightFutures/Dispatch+BrightFutures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public extension DispatchQueue {
}
}

public func asyncResult<T, E: Error>(_ execute: @escaping () -> Result<T, E>) -> Future<T, E> {
public func asyncResult<T, E>(_ execute: @escaping () -> Result<T, E>) -> Future<T, E> {
return Future { completion in
async {
completion(execute())
Expand Down
6 changes: 3 additions & 3 deletions Sources/BrightFutures/ExecutionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public let MaxStackDepthExecutionContext: ExecutionContext = { task in
}
}

typealias ThreadingModel = () -> ExecutionContext
public typealias ThreadingModel = () -> ExecutionContext

var DefaultThreadingModel: ThreadingModel = defaultContext
public var DefaultThreadingModel: ThreadingModel = defaultContext

/// Defines BrightFutures' default threading behavior:
/// - if on the main thread, `DispatchQueue.main.context` is returned
/// - if off the main thread, `DispatchQueue.global().context` is returned
func defaultContext() -> ExecutionContext {
public func defaultContext() -> ExecutionContext {
return (Thread.isMainThread ? DispatchQueue.main : DispatchQueue.global()).context
}
6 changes: 3 additions & 3 deletions Sources/BrightFutures/Future.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class Future<T, E: Error>: Async<Result<T, E>> {

}

public func materialize<T, E: Error>(_ scope: ((T?, E?) -> Void) -> Void) -> Future<T, E> {
public func materialize<T, E>(_ scope: ((T?, E?) -> Void) -> Void) -> Future<T, E> {
return Future { complete in
scope { val, err in
if let val = val {
Expand All @@ -91,13 +91,13 @@ public func materialize<T>(_ scope: ((T) -> Void) -> Void) -> Future<T, NoError>
}
}

public func materialize<E: Error>(_ scope: ((E?) -> Void) -> Void) -> Future<Void, E> {
public func materialize<E>(_ scope: ((E?) -> Void) -> Void) -> Future<Void, E> {
return Future { complete in
scope { err in
if let err = err {
complete(.failure(err))
} else {
complete(.success())
complete(.success(()))
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions Tests/BrightFuturesTests/BrightFuturesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ extension BrightFuturesTests {
func testSkippedRecover() {
let e = self.expectation()

DispatchQueue.global().asyncValue { _ in
DispatchQueue.global().asyncValue {
3
}.recover { _ in
XCTFail("recover task should not be executed")
Expand Down Expand Up @@ -411,7 +411,7 @@ extension BrightFuturesTests {
DispatchQueue.global().asyncResult {
Result(error: NSError(domain: "NaN", code: 0, userInfo: nil))
}.recoverWith { _ in
return DispatchQueue.global().asyncValue { _ in
return DispatchQueue.global().asyncValue {
fibonacci(5)
}
}.onSuccess { value in
Expand Down Expand Up @@ -450,7 +450,8 @@ extension BrightFuturesTests {

let e = self.expectation()

f.zip(f1).onSuccess { (a, b) in
f.zip(f1).onSuccess { (arg) in
let (a, b) = arg
XCTAssertEqual(a, 1)
XCTAssertEqual(b, 2)
e.fulfill()
Expand Down Expand Up @@ -742,7 +743,7 @@ extension BrightFuturesTests {
let e = self.expectation()

let evenFuture: (Int) -> Future<Bool, NSError> = { i in
return DispatchQueue.global().asyncResult { err in
return DispatchQueue.global().asyncResult {
if i % 2 == 0 {
return Result(value: true)
} else {
Expand Down Expand Up @@ -1082,7 +1083,7 @@ extension BrightFuturesTests {
}
}

p.success()
p.success(())

self.waitForExpectations(timeout: 5, handler: nil)
}
Expand Down Expand Up @@ -1137,14 +1138,14 @@ extension XCTestCase {
}

func failingFuture<U>() -> Future<U, NSError> {
return DispatchQueue.global().asyncResult { error in
return DispatchQueue.global().asyncResult {
usleep(arc4random_uniform(100))
return Result(error: NSError(domain: "failedFuture", code: 0, userInfo: nil))
}
}

func succeedingFuture<U>(_ val: U) -> Future<U, NSError> {
return DispatchQueue.global().asyncResult { _ in
return DispatchQueue.global().asyncResult {
usleep(arc4random_uniform(100))
return Result(value: val)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BrightFuturesTests/FutureDebugTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FutureDebugTests: XCTestCase {
let expectedMessage = "\(fileName) at line \(line), func: \(function) - future completed"
let debugExpectation = self.expectation(description: "debugLogged")

f.onSuccess {
f.onSuccess { _ in
XCTAssertEqual(logger.lastLoggedMessage, expectedMessage)
debugExpectation.fulfill()
}
Expand All @@ -46,7 +46,7 @@ class FutureDebugTests: XCTestCase {
let f = Future<Void, NoError>(value: ()).debug(testIdentifier, logger: logger)
let debugExpectation = self.expectation(description: "debugLogged")

f.onSuccess {
f.onSuccess { _ in
XCTAssertEqual(logger.lastLoggedMessage, "Future \(self.testIdentifier) completed")
debugExpectation.fulfill()
}
Expand Down

0 comments on commit 7e08010

Please sign in to comment.