Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Young Rappel
Search
Sergio Fernández
July 05, 2017
Programming
0
33
The Young Rappel
Futures and Promises on Swift
Sergio Fernández
July 05, 2017
Tweet
Share
More Decks by Sergio Fernández
See All by Sergio Fernández
Zero To Hero
fdzsergio
1
58
Other Decks in Programming
See All in Programming
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
340
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
830
エディターってAIで操作できるんだぜ
kis9a
0
560
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
290
AIと協働し、イベントソーシングとアクターモデルで作る後悔しないアーキテクチャ Regret-Free Architecture with AI, Event Sourcing, and Actors
tomohisa
5
16k
2025 컴포즈 마법사
jisungbin
1
170
CSC305 Lecture 15
javiergs
PRO
0
220
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
180
Micro Frontendsで築いた 共通基盤と運用の試行錯誤 / Building a Shared Platform with Micro Frontends: Operational Learnings
kyntk
1
1.9k
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
110
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
210
Google Antigravity and Vibe Coding: Agentic Development Guide
mickey_kubo
2
120
Featured
See All Featured
A Tale of Four Properties
chriscoyier
162
23k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
70
Unsuck your backbone
ammeep
671
58k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
Writing Fast Ruby
sferik
630
62k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Making Projects Easy
brettharned
120
6.5k
Being A Developer After 40
akosma
91
590k
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