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
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
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
firstly { | |
return fetch(url:url) | |
}.then{ | |
... | |
} |
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
firstly { | |
fetch(url: url) | |
}.ensure { | |
cleanup() | |
}.catch { | |
handle(error: $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
func fetch(url: URL) -> Promise<Data> { | |
return Promise { seal in | |
URLSession.shared.dataTask(with: url!) { data, _, error in | |
seal.resolve(data, error) | |
}.resume() | |
} | |
} | |
firstly { |
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
firstly { | |
fetch(url: url) | |
}.get { data in | |
//… | |
}.done { data in | |
// same data! | |
} |
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
firstly { | |
when(fulfilled: promise1(), promise2()) | |
}.done { result1, result2 in | |
//… | |
} |
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: url).then(on: .global(QoS: .userInitiated)) { | |
//then closure executes on different thread | |
} |
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
let waitAtLeast = after(seconds: 0.3) | |
firstly { | |
fetch(url: url) | |
}.then { | |
waitAtLeast | |
}.done { | |
//… | |
} |