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
Comparative Asynchronous Programming
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Ash Furrow
February 24, 2017
Programming
9.8k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Comparative Asynchronous Programming
Presented at Playgrounds Conf:
http://www.playgroundscon.com/
Ash Furrow
February 24, 2017
More Decks by Ash Furrow
See All by Ash Furrow
My Slow Return to a Swift Career
ashfurrow
0
26
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
350
How Artsy Automates Team Culture
ashfurrow
0
3.4k
Building Custom TSLint Rules
ashfurrow
0
530
Circumventing Fear of the Unknown
ashfurrow
1
600
Building Better Software by Building Better Teams
ashfurrow
1
700
Building Open Source Communities
ashfurrow
0
1k
Building Compassionate Software
ashfurrow
0
590
Swift, Briskly
ashfurrow
0
210
Other Decks in Programming
See All in Programming
Security issues being discussed on Web Platforms
petamoriken
0
1k
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
550
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
SREの越境 / SRE Collaboration
y0hgi
2
260
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
200
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
190
App Intentsのビルドプロセスを支える技術
kntkymt
0
410
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
500
Java 27新機能 / Java 27 new features
kishida
2
150
What We Talk About When We Talk About XP
m_seki
2
670
Webの地図
yosuke_furukawa
PRO
6
4.7k
Featured
See All Featured
Unsuck your backbone
ammeep
672
58k
How to train your dragon (web standard)
notwaldorf
97
6.8k
4 Signs Your Business is Dying
shpigford
187
23k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
280
GraphQLとの向き合い方2022年版
quramy
50
15k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
430
Odyssey Design
rkendrick25
PRO
2
810
Building Adaptive Systems
keathley
44
3.2k
Documentation Writing (for coders)
carmenintech
77
5.5k
Transcript
Comparative Asynchronous Programming
None
Agenda 1. Asynchronous programming is hard. 2. Swift already supports
a few async methodologies. 3. Swift supports some other paradigms. 4. But lacks support for others.
Asynchronous Programming: Difficult and Subjective
“Normal” programming
let returnValue = someFunctionCall()
Asynchronous programming
Development is all about tradeoffs
let file = readFile() ... readFile() { file in ...
}
Embrace Tradeoffs
Swift Has Async Built-in. Sorta.
Built-in Async Approaches
Grand Central Dispatch
NSOperationQueue / DRBOperationTree
POSIX Threads
Target / Action
Callbacks / Completion Handlers
logIn(with: credentials) { result in // Handle login success or
failure }
Callback Hell
getCredentialsFromUser() { credentials in logIn(with: credentials) { result in //
Handle login success or failure } }
getCredentialsFromUser() { credentials, error in if credentials { logIn(with: credentials)
{ login, error in if login { // Handle login success } else { // Handle error } } } else { // Handle error } }
(credentials: Credentials?) -> Void (credentials: Credentials?, error: Error?) -> Void
(result: Result<Credentials>) -> Void
enum Result<T> { case success(T) case error(Error) }
Callback Heaven
Some Async Abstractions are Supported in Swift
Promises & Futures
getCredentialsFromUser() .flatMap { credentials in return login(with: credentials) } .onSuccess
{ login in // Handle login success } .onFailure { error in // Handle login error }
Functional Reactive Programming
getCredentialsFromUser() .flatMap { credentials in return login(with: credentials) } .on(next:
{ login in // Handle login success }, error: { error in // Handle login error })
None
gerstureRecognizer.rx .event .map { recognizer in return recognizer.location(in: recognizer.view) }
.bind(to: circle.rx.center)
Actor Model
None
Actor Model
Some Async Abstractions are Impossible in Swift
Async / Await
async func logIn() -> Login { let credentials = await
getCredentialsFromUser() return await logIn(with: credentials) }
Coroutines and Generator Functions
func fibGenerator*() -> Int { var i = 0, j
= 1 repeat { let next = i + j yield next (i, j) = (j, next) } while true } fibGenerator() // returns 1 fibGenerator() // returns 2 fibGenerator() // returns 3 fibGenerator() // returns 5
Wrap Up 1. There’s no “right way” to do async
programming. 2. Asynchronous abstractions built into Swift aren’t great. 3. There are some cool things you can do in Swift. 4. There are other cool things that you can’t do in Swift.
None