Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The Young Rappel
Search
Sergio Fernández
July 05, 2017
Programming
37
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Young Rappel
Futures and Promises on Swift
Sergio Fernández
July 05, 2017
More Decks by Sergio Fernández
See All by Sergio Fernández
Zero To Hero
fdzsergio
1
66
Other Decks in Programming
See All in Programming
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
4
3.5k
Next.js: The final boss of Web Performance
guaca
0
250
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
AWSに止められる覚悟してますか?
morizo_1984
2
530
Jetpack Compose Mechanisms
skydoves
3
820
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Raft: Consensus for Rubyists
vanstee
142
7.8k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
Git: the NoSQL Database
bkeepers
PRO
433
67k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
600
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
Transcript
The Young Rappel Futures & Promises
Hi! I'm Sergio @fdzsergio
Agenda Working with asynchronous tasks Deferred computations Back to the
Future
Async is hard
Request Image login(with: credentials) { (result: JSONResponse) in if case
.success(let json) = result, let user = User(with: json) { fetch(avatar: user.avatarURL) { (result: DataResponse) in if case .success(let data) = result { let image = UIImage(data: data) self.imageView = UIImageView(image: image) } } } }
then
Request Image login(with: credentials) .then(User.init) .then { user in return
fetch(avatar: user.avatarURL) }.then { data in self.imageView.image = UIImage(data: data) }.catch { error in // handle error } }
Futures & Promises It is the way to handle complex
asynchronous operations in a simple way
What the heck is a Future?
Future is an object that represents that you will get
something in the future.
Future let login: Promise<User> = login(with: credentials) login.then { user
in self.storage.save(user) }
What is a Promise?
A promise is an object that may produce a single
value some time in the future
Promise func login(with credentials: Credentials) -> Promise<User> { return Promise
{ fulfill, reject in self.client.request(task: .login(credentials)) { result in switch result { case .success(let json): fulfill(User(with: json)) case .failure(let error): reject(error) } } } }
Common Functions → then → catch → always → when
→ all
Limitations of Futures → Promises can only produce one value
→ Can nwot encapsulate streams of values → Only consumer driven
Back to the Future → Abstraction for async/sync operations →
Encapsulate a deferred computation → Centralized error handling → Easily composable
DeLorean
B-Sides → https://promisesaplus.com → http://khanlou.com/2016/08/promises-in-swift → https://speakerdeck.com/javisoto/back-to-the- futures → https://medium.com/compileswift/hydra-
promises-swift-c6319f6a6209
The Future is Today. — William Osler
Thank You!
Questions? @fdzsergio