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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
300
How Artsy Automates Team Culture
ashfurrow
0
3.3k
Building Custom TSLint Rules
ashfurrow
0
470
Circumventing Fear of the Unknown
ashfurrow
1
580
Building Better Software by Building Better Teams
ashfurrow
1
650
Building Open Source Communities
ashfurrow
0
960
Building Compassionate Software
ashfurrow
0
530
Swift, Briskly
ashfurrow
0
190
iOS Checkup
ashfurrow
1
910
Other Decks in Programming
See All in Programming
AIを導入する前にやるべきこと
negima
2
340
t *testing.T は どこからやってくるの?
otakakot
1
910
KMP × Kotlin 2.3 - How Android Got Slower While iOS Builds Improved by 47%
rio432
0
140
2026年のソフトウェア開発を考える(2026/05版) / Software Engineering Scrum Fest Niigata 2026 Edition
twada
PRO
22
11k
🦞OpenClaw works with AWS
licux
1
340
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
4
450
PHPer、Cloudflare に引っ越す
suguruooki
1
140
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
250
継続的な負荷検証を目指して
pyama86
2
900
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
150
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
350
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
820
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
440
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
230
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
160
WCS-LA-2024
lcolladotor
0
580
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
From π to Pie charts
rasagy
0
180
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