Skip to content

Commit

Permalink
Cleaning project
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickl committed Aug 19, 2017
1 parent b5d4494 commit 3a87211
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 74 deletions.
64 changes: 32 additions & 32 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}
84 changes: 43 additions & 41 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,53 @@ import PromiseKit
import AwaitKit

struct User {
var name: String
var name: String
}

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

async {
throw NSError(domain: "com.yannickloriot.error", code: 3, userInfo: nil)
}

let user = try! await(signIn(username: "Foo", password: "Bar"))
try! await(sendWelcomeMailToUser(user))
try! await(redirectToThankYouScreen())

print("All done with \(user)!")
}

// MARK: - Promises

func signIn(username name: String, password: String) -> Promise<User> {
return Promise { resolve, reject in
resolve(User(name: name))
}
override func viewDidLoad() {
super.viewDidLoad()

// Async block catch the exceptions
async {
throw NSError(domain: "com.yannickloriot.error", code: 3, userInfo: nil)
}

func sendWelcomeMailToUser(_ user: User) -> Promise<Void> {
return Promise { resolve, reject in
let deadlineTime = DispatchTime.now() + .seconds(1)
let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent)

queue.asyncAfter(deadline: deadlineTime, execute: {
resolve()
})
}

let user = try! await(signIn(username: "Foo", password: "Bar"))
try! await(sendWelcomeMailToUser(user))
try! await(redirectToThankYouScreen())

print("All done with \(user)!")
}

// MARK: - Promises

func signIn(username name: String, password: String) -> Promise<User> {
print("signIn")
return async { User(name: name) }
}

func sendWelcomeMailToUser(_ user: User) -> Promise<Void> {
print("sendWelcomeMailToUser")
return Promise { resolve, reject in
let deadlineTime = DispatchTime.now() + .seconds(1)
let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent)

queue.asyncAfter(deadline: deadlineTime, execute: {
resolve()
})
}

func redirectToThankYouScreen() -> Promise<Void> {
return Promise { resolve, reject in
let deadlineTime = DispatchTime.now() + .seconds(1)
let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent)

queue.asyncAfter(deadline: deadlineTime, execute: {
resolve()
})
}
}

func redirectToThankYouScreen() -> Promise<Void> {
print("redirectToThankYouScreen")
return Promise { resolve, reject in
let deadlineTime = DispatchTime.now() + .seconds(1)
let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent)

queue.asyncAfter(deadline: deadlineTime, execute: {
resolve()
})
}
}
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ import PackageDescription
let package = Package(
name: "AwaitKit",
dependencies: [
.Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 4, minor: 2)
.Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 4, minor: 3)
]
)

0 comments on commit 3a87211

Please sign in to comment.