Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Comparative Asynchronous Programming
Search
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
18
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
320
How Artsy Automates Team Culture
ashfurrow
0
3.4k
Building Custom TSLint Rules
ashfurrow
0
510
Circumventing Fear of the Unknown
ashfurrow
1
590
Building Better Software by Building Better Teams
ashfurrow
1
690
Building Open Source Communities
ashfurrow
0
1k
Building Compassionate Software
ashfurrow
0
560
Swift, Briskly
ashfurrow
0
200
Other Decks in Programming
See All in Programming
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
160
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
5
1.9k
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
230
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
440
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
670
メールのエイリアス機能を履き違えない
isshinfunada
0
250
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
520
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
0
130
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
340
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
240
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
330
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Into the Great Unknown - MozCon
thekraken
41
2.7k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
630
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
340
Producing Creativity
orderedlist
PRO
348
40k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Spectacular Lies of Maps
axbom
PRO
1
930
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
170
Building the Perfect Custom Keyboard
takai
2
840
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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