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

Commit

Permalink
Merge branch 'Noobish1-feature/swift2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomvis committed Apr 7, 2016
2 parents 107256d + 56eb02d commit 5869a3e
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 29 deletions.
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: xcode7.1
osx_image: xcode7.3

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 = '3.3.1'
s.version = '4.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 @@ -15,7 +15,7 @@ Pod::Spec.new do |s|

s.source_files = 'BrightFutures/*.swift'

s.dependency 'Result', '~> 1.0'
s.dependency 'Result', '~> 2.0'

s.requires_arc = true
end
2 changes: 1 addition & 1 deletion BrightFutures/AsyncType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

public protocol AsyncType {
typealias Value
associatedtype Value

var result: Value? { get }

Expand Down
24 changes: 11 additions & 13 deletions BrightFutures/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@
// SOFTWARE.

import Foundation

/// Can be used as the value type of a `Future` or `Result` to indicate it can never fail.
/// This is guaranteed by the type system, because `NoError` has no possible values and thus cannot be created.
public enum NoError {}

extension NoError: Equatable { }

public func ==(lhs: NoError, rhs: NoError) -> Bool {
return true
}

/// Extends `NoError` to conform to `ErrorType`
extension NoError: ErrorType {}
import Result

/// An enum representing every possible error for errors returned by BrightFutures
/// A `BrightFuturesError` can also wrap an external error (e.g. coming from a user defined future)
Expand All @@ -60,3 +48,13 @@ public func ==<E: Equatable>(lhs: BrightFuturesError<E>, rhs: BrightFuturesError
default: return false
}
}

/// Returns `true` if `left` and `right` are both of the same case ignoring .External associated value
public func ==(lhs: BrightFuturesError<NoError>, rhs: BrightFuturesError<NoError>) -> Bool {
switch (lhs, rhs) {
case (.NoSuchElement, .NoSuchElement): return true
case (.InvalidationTokenInvalidated, .InvalidationTokenInvalidated): return true
case (.External(_), .External(_)): return true // this cannot happen because NoError cannot be instantiated
default: return false
}
}
1 change: 1 addition & 0 deletions BrightFutures/InvalidationToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import Result

/// The type that all invalidation tokens conform to
public protocol InvalidationTokenType {
Expand Down
10 changes: 5 additions & 5 deletions BrightFuturesTests/BrightFuturesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ extension BrightFuturesTests {
f.onSuccess { fibSeq in
XCTAssertEqual(fibSeq.count, n)

for var i = 0; i < fibSeq.count; i++ {
for i in 0 ..< fibSeq.count {
XCTAssertEqual(fibSeq[i], fibonacci(i+1))
}
e.fulfill()
Expand Down Expand Up @@ -1124,12 +1124,12 @@ extension BrightFuturesTests {
p.future.onComplete(Queue.global.context) { _ in
XCTAssert(executingCallbacks == 0, "This should be the only executing callback")

executingCallbacks++
executingCallbacks += 1

// sleep a bit to increase the chances of other callback blocks executing
NSThread.sleepForTimeInterval(0.06)

executingCallbacks--
executingCallbacks -= 1

e.fulfill()
}
Expand All @@ -1138,12 +1138,12 @@ extension BrightFuturesTests {
p.future.onComplete(Queue.main.context) { _ in
XCTAssert(executingCallbacks == 0, "This should be the only executing callback")

executingCallbacks++
executingCallbacks += 1

// sleep a bit to increase the chances of other callback blocks executing
NSThread.sleepForTimeInterval(0.06)

executingCallbacks--
executingCallbacks -= 1

e1.fulfill()
}
Expand Down
3 changes: 2 additions & 1 deletion BrightFuturesTests/InvalidationTokenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import XCTest
import BrightFutures
import Result

class InvalidationTokenTests: XCTestCase {

Expand Down Expand Up @@ -120,7 +121,7 @@ class InvalidationTokenTests: XCTestCase {

q.sync {
token.invalidate()
counter.i++
counter.i += 1
}
}

Expand Down
4 changes: 2 additions & 2 deletions BrightFuturesTests/NSOperationQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class NSOperationQueueTests: XCTestCase {
let e = self.expectation()
queue.context {
sem.execute {
i++
i += 1
}
XCTAssert(i <= queue.maxConcurrentOperationCount)

sem.execute {
i--
i -= 1
}
XCTAssert(i >= 0)

Expand Down
3 changes: 2 additions & 1 deletion BrightFuturesTests/QueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import XCTest
import BrightFutures
import Result

class QueueTests: XCTestCase {

Expand All @@ -40,7 +41,7 @@ class QueueTests: XCTestCase {
func testSync() {
var i = 1
Queue.global.sync {
i++
i += 1
}
XCTAssert(i == 2, "sync should execute the block synchronously")
}
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" ~> 1.0
github "antitypical/Result" ~> 2.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" "1.0.1"
github "antitypical/Result" "2.0.0"

0 comments on commit 5869a3e

Please sign in to comment.