then 0

Promises Library for Swift :clapper:

Then

then

Language: Swift 2 and 3 Platform: iOS 8+ Carthage compatible Cocoapods compatible Build Status codebeat badge Join the chat at https://gitter.im/s4cha/then License: MIT [Release version]()

Reason - Example - Installation

fetchUserId().then { id in
    print("UserID : \(id)")
}.onError { e in
    print("An error occured : \(e)")
}.finally {
    print("Everything is Done :)")
}

Swift Version

Swift 2 -> version 1.4.2
Swift 3 -> version 2.0.1

Why

Because async code is hard to write, hard to read, hard to reason about.
A pain to maintain

How

By using a then keyword that enables you to write aSync code that reads like an English sentence
Async code is now concise, flexible and maintainable ❤️

What

  • [x] Based on the popular Promise/Future concept
  • [x] Lightweight (1 file ~100lines)
  • [x] Pure Swift
  • [x] No magic involved
  • [x] Strongly Typed
  • [x] Chainable

Example

Before


fetchUserId({ id in
    fetchUserNameFromId(id, success: { name in
        fetchUserFollowStatusFromName(name, success: { isFollowed in
            // The three calls in a row succeeded YAY!
            reloadList()
        }, failure: { error in
            // Fetching user ID failed
            reloadList()
        })
    }, failure: { error in
        // Fetching user name failed
        reloadList()
    })
}) {  error in
    // Fetching user follow status failed
    reloadList()
}

Related Repositories

rspec-given

rspec-given

Given/When/Then keywords for RSpec Specifications ...

then-redis

then-redis

A fast, promise-based Redis client for node.js ...

then-request

then-request

A request library that returns promises, inspired by request ...

rspec-given

rspec-given

Given/When/Then keywords for RSpec Specifications ...

then-chrome

then-chrome

Promise-based chrome-api ...


Top Contributors

s4cha ksmandersen neoneye gitter-badger tmcw

Releases

-   v0.2.1 zip tar
-   v0.2 zip tar
-   v0.1.1 zip tar
-   v0.1 zip tar
-   2.0.0 zip tar
-   1.4.2 zip tar
-   1.4.1 zip tar
-   1.4.0 zip tar
-   1.3.0 zip tar
-   1.2.2 zip tar
-   1.2.1 zip tar
-   1.2.0 zip tar
-   1.1.0 zip tar
-   1.0.0 zip tar