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
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
25
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
340
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
580
Swift, Briskly
ashfurrow
0
210
Other Decks in Programming
See All in Programming
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.5k
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
180
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
2.8k
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
700
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.8k
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
430
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
360
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
190
setup-vp GitLab対応の裏側
naokihaba
0
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
210
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
Featured
See All Featured
Believing is Seeing
oripsolob
1
220
Making the Leap to Tech Lead
cromwellryan
135
10k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1k
Code Reviewing Like a Champion
maltzj
528
40k
Become a Pro
speakerdeck
PRO
31
6.3k
A designer walks into a library…
pauljervisheath
211
25k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Six Lessons from altMBA
skipperchong
29
4.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
340
sira's awesome portfolio website redesign presentation
elsirapls
0
420
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
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