❤️ Support my app ❤️
- Push Hero - pure Swift native macOS application to test push notifications
- PastePal - Pasteboard, note and shortcut manager
- Frame recorder - Recorder gif and video with frame
- Alias - App and file shortcut manager
- Other apps
❤️❤️😇😍🤘❤️❤️
Promise A+ in Swift
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Use Result to associate states with values
- Support protocol
Thenable
- Support queue
- Transform Fulfilled value
let promise = Promise<Int>()
promise.then { result in
var condition = false
if case let .Fulfilled(value) = result where value == 10 {
condition = true
}
XCTAssert(condition)
return nil
} as Promise<Any>
promise.fulfill(value: 10)
let promise = (Promise<String>(result: .Fulfilled(value: "then"))
.then { result in
return result.map { value in
return value.characters.count
}
} as Promise<Int>)
.then { result in
return result.map { value in
return value * 2
}
} as Promise<Int>
promise.then { result in
if case let .Fulfilled(value) = result {
XCTAssert(value == 8)
} else {
XCTAssert(false)
}
return nil
} as Promise<Any>
}
let promise1 = Promise<Int>(result: .Fulfilled(value: 1))
let promise2 = Promise<Int>(result: .Fulfilled(value: 2))
let promise3 = Promise<Int>(result: .Fulfilled(value: 3))
let final = Promise.all(promises: [promise1, promise2, promise3])
final.then { result in
if case let .Fulfilled(value) = result {
XCTAssert(value.count == 3)
XCTAssert(value.values.contains(1))
XCTAssert(value.values.contains(2))
XCTAssert(value.values.contains(3))
XCTAssert(value.keys.contains(promise1.key))
} else {
XCTAssert(false)
}
return nil
} as Promise<Any>
Then is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Then', git: 'https://github.com/onmyway133/Then'
Khoa Pham, [email protected]
Then is available under the MIT license. See the LICENSE file for more info.