Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onmyway133/then
:runner: Promise A+ in Swift
https://github.com/onmyway133/then
ios promise swift
Last synced: 3 months ago
JSON representation
:runner: Promise A+ in Swift
- Host: GitHub
- URL: https://github.com/onmyway133/then
- Owner: onmyway133
- License: mit
- Created: 2015-12-28T18:02:02.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T20:42:30.000Z (almost 5 years ago)
- Last Synced: 2024-09-24T12:45:40.361Z (4 months ago)
- Topics: ios, promise, swift
- Language: Swift
- Homepage: https://onmyway133.github.io/
- Size: 42 KB
- Stars: 11
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Then
❤️ Support my app ❤️
- [Push Hero - pure Swift native macOS application to test push notifications](https://www.producthunt.com/posts/push-hero-2)
- [PastePal - Pasteboard, note and shortcut manager](https://www.producthunt.com/posts/pastepal)
- [Frame recorder - Recorder gif and video with frame](https://www.producthunt.com/posts/frame-recorder)
- [Alias - App and file shortcut manager](https://www.producthunt.com/posts/alias-shortcut-manager)
- [Other apps](https://onmyway133.github.io/projects/)❤️❤️😇😍🤘❤️❤️
[Promise A+](https://promisesaplus.com/) in Swift
## Usage
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Features
- Use Result to associate states with values
- Support protocol `Thenable`
- Support queue
- Transform Fulfilled value### Then
```swift
let promise = Promise()promise.then { result in
var condition = false
if case let .Fulfilled(value) = result where value == 10 {
condition = true
}XCTAssert(condition)
return nil
} as Promisepromise.fulfill(value: 10)
```### Chain
```swift
let promise = (Promise(result: .Fulfilled(value: "then"))
.then { result in
return result.map { value in
return value.characters.count
}
} as Promise)
.then { result in
return result.map { value in
return value * 2
}
} as Promisepromise.then { result in
if case let .Fulfilled(value) = result {
XCTAssert(value == 8)
} else {
XCTAssert(false)
}return nil
} as Promise
}
```### All
```swift
let promise1 = Promise(result: .Fulfilled(value: 1))
let promise2 = Promise(result: .Fulfilled(value: 2))
let promise3 = Promise(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
```## Installation
Then is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'Then', git: 'https://github.com/onmyway133/Then'
```## Author
Khoa Pham, [email protected]
## License
Then is available under the MIT license. See the LICENSE file for more info.