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
2
9.4k
Comparative Asynchronous Programming
Presented at Playgrounds Conf:
http://www.playgroundscon.com/
Ash Furrow
February 24, 2017
Tweet
Share
More Decks by Ash Furrow
See All by Ash Furrow
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
220
How Artsy Automates Team Culture
ashfurrow
0
3k
Building Custom TSLint Rules
ashfurrow
0
400
Circumventing Fear of the Unknown
ashfurrow
1
500
Building Better Software by Building Better Teams
ashfurrow
1
540
Building Open Source Communities
ashfurrow
0
830
Building Compassionate Software
ashfurrow
0
410
Swift, Briskly
ashfurrow
0
130
iOS Checkup
ashfurrow
1
830
Other Decks in Programming
See All in Programming
TSConfig Solution Style & subpath imports to switch types on a per-file basis
maminami373
1
180
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
1.6k
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfold' relates to 'iterate'"
philipschwarz
PRO
0
140
DevTalks 25 - Create your own AI-infused Java apps with ease
kdubois
2
130
RubyKaigi Hack Space in Tokyo & 函館最速 "予習" 会 / RubyKaigi Hack Space in Tokyo & The Fastest Briefing of RubyKaigi 2026 in Hakodate
moznion
1
130
TypeScript を活かしてデザインシステム MCP を作る / #tskaigi_after_night
izumin5210
4
490
ワイがおすすめする新潟の食 / 20250530phpconf-niigata-eve
kasacchiful
0
280
20250528 AWS Startupイベント登壇資料:AIコーディングの取り組み
procrustes5
0
110
Step up the performance game with Spring Boot and Project Leyden
mhalbritter
0
110
「兵法」から見る質とスピード
ickx
0
220
ソフトウェア品質特性、意識してますか?AIの真の力を引き出す活用事例 / ai-and-software-quality
minodriven
19
6.7k
當開發遇上包裝:AI 如何讓產品從想法變成商品
clonn
0
2.7k
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Embracing the Ebb and Flow
colly
85
4.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Side Projects
sachag
454
42k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
What's in a price? How to price your products and services
michaelherold
245
12k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
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