This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(url: <imageurl>).recover { error -> Promise<UIImage> in | |
return UIImage(name: <placeholder>) | |
}... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(url: <backend-url>).then { value in | |
// value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetch(url: URL) -> Promise<Data> { | |
return Promise { seal in | |
URLSession.shared.dataTask(with: url!) { data, _, error in | |
seal.resolve(data, error) | |
}.resume() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Guarantee { seal in | |
seal("Hello World") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetch(url: URL) -> Promise<Data> { | |
return Promise { seal in | |
URLSession.shared.dataTask(with: url!) { data, _, error in | |
seal.resolve(data, error) | |
}.resume() | |
} | |
} | |
fetch(url: <backendURL>).then { data in | |
return JSONParsePromise(data) // we skip the wrapping of JSONParsing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package.dependencies.append( | |
.Package(url: "https://github.com/mxcl/PromiseKit", majorVersion: 6) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github "mxcl/PromiseKit" ~> 6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_frameworks! | |
target "target" do | |
pod "PromiseKit", "~> 6.0" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchPromise().then { value in | |
return errorPromise(value) // this will throw an error | |
}.then { value in | |
//this will not execute on error | |
}.catch { error in | |
//we got an error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchPromise().then { value in | |
return fetchPromise2(value) | |
}.then { value in | |
// do something | |
}.catch { error in | |
// error | |
} |