<commit_before>
SPKit is just another Swift promises framework, it prevents the **_callback hell_** and supports sync and async code.  
It was made be to simple to use, read and maintain.  
It works with Xcode 8 and Swift 3  

### How to install SPKit  
You can install SPKit using carthage, or just drag the SPKit.swift file to your project.  

### How to use SPKit  

Start the flow by calling `SPKit.first`, move to the next block by calling `.resolve()` and finish the flow by calling `.complete()` or `.failure()`.

#### Example happy path
```swift
SPKit.first { (instance) in
	print("first code exec")
	instance.resolve()
}.then { (instance, result) in
    DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)){
        print("async code")
        instance.resolve()
    }
}.then { (instance, result) in
    print("sync code")
    instance.resolve("finished stage 2")
}.then { (instance, result) in  
	print("using result value: \(result as? String ?? "")")
    instance.complete()
}.onCompleted {(result) in
    print("COMPLETED")
}.onFailure {(error) in
    print("FAILURE")
}
```

#### Example error path
```swift
SPKit.first { (instance) in
	print("first code exec")
	instance.resolve()
}.then { (instance, result) in
    DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)){
        print("async code")
        instance.resolve()
    }
}.then { (instance, result) in
    print("sync code")
    instance.resolve("finished stage 2")
}.then { (instance, result) in
	print("using result value: \(result as? String ?? "")")
    instance.failure("ooppps")
}.onCompleted {(result) in
    print("COMPLETED")
}.onFailure {(error) in
    print("FAILURE")
}
```

##### Doubts or questions 
Please open an issue.
  
    
  

![Build](https://www.bitrise.io/app/93bb51c1de5dd228.svg?token=QzEV4V8xkznqBPDKyChWLA&branch=swift3)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 
![Swift version](https://img.shields.io/badge/Swift%20-3.x-orange.svg) 
![platforms](https://img.shields.io/badge/platforms-iOS-lightgrey.svg)  
<commit_msg>improvements<commit_after>
SPKit is just another Swift promises framework, it prevents the **_callback hell_** and supports sync and async code.  
It was made be to simple to use, read and maintain.  
It works with Xcode 8 and Swift 3  

### How to install SPKit  
You can install SPKit using carthage, or just drag the SPKit.swift file to your project.  

### How to use SPKit  

Start the flow by calling `SPKit.first`, move to the next block by calling `.resolve()` and finish the flow by calling `.complete()` or `.failure()`.

#### Example happy path
```swift
SPKit.first { (instance) in
	print("first code block")
	instance.resolve()
}.then { (instance, result) in  
	print("next code block")
    instance.complete()
}.onCompleted {(result) in
    print("COMPLETED")
}.onFailure {(error) in
    print("FAILURE")
}
```

#### Example happy path with sync and async
```swift
SPKit.first { (instance) in
	print("first code exec")
	instance.resolve()
}.then { (instance, result) in
    DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)){
        print("async code")
        instance.resolve()
    }
}.then { (instance, result) in
    print("sync code")
    instance.resolve("finished stage 2")
}.then { (instance, result) in  
	print("using result value: \(result as? String ?? "")")
    instance.complete()
}.onCompleted {(result) in
    print("COMPLETED")
}.onFailure {(error) in
    print("FAILURE")
}
```

#### Example error path
```swift
SPKit.first { (instance) in
	print("first code exec")
	instance.resolve()
}.then { (instance, result) in
    print("sync code")
    instance.resolve("finished stage 2")
}.then { (instance, result) in
	print("using result value: \(result as? String ?? "")")
    instance.failure("ooppps")
}.onCompleted {(result) in
    print("COMPLETED")
}.onFailure {(error) in
    print("FAILURE")
}
```

##### Doubts or questions 
Please open an issue.
  
    
  

![Build](https://www.bitrise.io/app/93bb51c1de5dd228.svg?token=QzEV4V8xkznqBPDKyChWLA&branch=swift3)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 
![Swift version](https://img.shields.io/badge/Swift%20-3.x-orange.svg) 
![platforms](https://img.shields.io/badge/platforms-iOS-lightgrey.svg)  

{'fraction_non_alphanumeric': 0.1569334836527621, 'fraction_numerical': 0.010597519729425029, 'mean_word_length': 4.040909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3761024', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1417, 'n_words': 411}