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.7k
2
Share
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
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
290
How Artsy Automates Team Culture
ashfurrow
0
3.3k
Building Custom TSLint Rules
ashfurrow
0
460
Circumventing Fear of the Unknown
ashfurrow
1
570
Building Better Software by Building Better Teams
ashfurrow
1
630
Building Open Source Communities
ashfurrow
0
940
Building Compassionate Software
ashfurrow
0
520
Swift, Briskly
ashfurrow
0
180
iOS Checkup
ashfurrow
1
900
Other Decks in Programming
See All in Programming
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
110
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
130
20260320登壇資料
pharct
0
160
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
130
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
830
Running Swift without an OS
kishikawakatsumi
0
360
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
250
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
540
PHPのバージョンアップ時にも役立ったAST(2026年版)
matsuo_atsushi
0
290
一度始めたらやめられない開発効率向上術 / Findy あなたのdotfilesを教えて!
k0kubun
4
2.8k
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
120
Rethinking API Platform Filters
vinceamstoutz
0
11k
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
We Have a Design System, Now What?
morganepeng
55
8.1k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
800
Designing Powerful Visuals for Engaging Learning
tmiket
1
330
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
220
Are puppies a ranking factor?
jonoalderson
1
3.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
500
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
The Language of Interfaces
destraynor
162
26k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Accessibility Awareness
sabderemane
0
94
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