SlideShare a Scribd company logo
Future/Promise on iOS
Thinh VoXuan
Summer 2016
1. Callback hell & Another problem
2. What is promise ?
3. Chaining tasks pattern
4. Parallel tasks pattern
5. Errors handler
6. Example with Bolt Framework
7. Advantages
Agenda
Future/Promise on iOS
2
• Synchronous vs Asynchronous
Not Today
Future/Promise on iOS
3
Callback hell & Another problems
Future/Promise on iOS
4
Callback hell & Another problems
Future/Promise on iOS
5
Callback hell & Another problems
Future/Promise on iOS
6
Callback hell & Another problems
Future/Promise on iOS
7
How could I call 3 requests on same times?
Callback hell & Another problems
Future/Promise on iOS
8
Hard to understand
and follow the logic ?
What happen when
1 request has error?
What is promise ?
Future/Promise on iOS
9
• Deferred State
• pending
• Settled State
• fulfilled
• rejected
What is promise ? - fulfilled
Future/Promise on iOS
10
fulfilled could be
•Value
•Object
•Another Promise
What is promise ? - rejected
Future/Promise on iOS
11
rejected could be
•Error
Chaining tasks pattern
Future/Promise on iOS
12
• continueWith: Enqueues a given closure
to be run once this task is complete.
• continueWithTask: This is the method that
all other continuations must go through.
• continueOnSuccessWith
(continueOnSuccessWithTask): Enqueues
a given closure to be run once this task
completes with success (has intended
result).
• continueOnErrorWith
(continueOnErrorWithTask): Enqueues a
given closure to be run once this task
completes with error.
Chaining tasks pattern
Future/Promise on iOS
13
Chaining tasks pattern
Future/Promise on iOS
14
Chaining tasks pattern
Future/Promise on iOS
15
Chaining tasks pattern - continueWith
Future/Promise on iOS
16
Chaining tasks pattern
Future/Promise on iOS
17
Parallel tasks pattern
Future/Promise on iOS
18
• whenAll : Creates a task that will be completed
after all of the input tasks have completed.
• whenAllResult: Like whenAll. The result of the
task is going an array of results of all tasks in the
same order as they were provided.
• whenAny: Creates a task that will complete when
any of the input tasks have completed.
Parallel tasks pattern
Future/Promise on iOS
19
Parallel tasks pattern - whenAll
Future/Promise on iOS
20
Parallel tasks pattern - whenAllResult
Future/Promise on iOS
21
Parallel tasks pattern – whenAny
Future/Promise on iOS
22
Could only go with tasks on function
•continueWith
•continueOnErrorWith
If error occurs next task on
continueOnSuccessWith will never run
Errors handler
Future/Promise on iOS
23
• How to create Promise from
Asynchronous function
• How to create Promise from Synchronous
function
BoltFramework
Future/Promise on iOS
24
BoltFramework – Create Promise
Future/Promise on iOS
25
BoltFramework/Bolt-Swift
BoltFramework – Create Promise
Future/Promise on iOS
26
BoltFramework/Bolt-ObjC
• Readable code
• Testable code
• Component task
• Re-useable code
Advantages
Future/Promise on iOS
27
Chaining tasks pattern - continueOnSuccessWith
Future/Promise on iOS
28
References
Future/Promise on iOS
29
• https://github.com/BoltsFramework/Bolts-Swift
• https://github.com/BoltsFramework/Bolts-ObjC
• http://www.slideshare.net/NicholasvandeWalle
Q&A
Future/Promise on iOS
30
Thank you
Future/Promise on iOS
31
• Software Engineer at GEEKUp company:
• iOS
• Web
• Scrum Master
• love sharing & technical excellent
• Website: http://thinhvoxuan.me
• Github: https://github.com/voxuanthinh
• Skype: voxuan.thinh
whoami
Future/Promise on iOS
32

More Related Content

PPT
Pomodoro
PDF
Swift girls 5th_teaching_meeting20160829
PPT
Starting with Reactjs
PPT
Ionic Framework
PDF
How would you describe Swift in three words?
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
Asynchronous Programming. Talk from ESUG2024
PDF
JavaScript, un langage plein de promesses
Pomodoro
Swift girls 5th_teaching_meeting20160829
Starting with Reactjs
Ionic Framework
How would you describe Swift in three words?
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous Programming. Talk from ESUG2024
JavaScript, un langage plein de promesses

Similar to Promise on iOs (20)

PDF
Promises, Promises: Mastering Async I/O in Javascript with the Promise Pattern
PPTX
Async discussion 9_29_15
PDF
JavaScript Promises Simplified [Free Meetup]
PPTX
Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, Thought...
PPTX
PDF
Promises - Asynchronous Control Flow
PDF
Promise of an API
PDF
Getting Comfortable with JS Promises
PDF
Async Await for Mobile Apps
PDF
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
PPTX
JavaScript Promises
PDF
The Talk You've Been Await-ing For
PDF
Asynchronous JavaScript Programming
PDF
Asynchronous development in JavaScript
PDF
Promises - The Unsung Heroes ofJavaScript
PPTX
Async all around us (promises)
PDF
CommitConf 2018 - Going Async With Kotlin
PPTX
Seastar Summit 2019: Past and future of futures
PDF
The art of concurrent programming
PPTX
Mobile Application Development class 008
Promises, Promises: Mastering Async I/O in Javascript with the Promise Pattern
Async discussion 9_29_15
JavaScript Promises Simplified [Free Meetup]
Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, Thought...
Promises - Asynchronous Control Flow
Promise of an API
Getting Comfortable with JS Promises
Async Await for Mobile Apps
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
JavaScript Promises
The Talk You've Been Await-ing For
Asynchronous JavaScript Programming
Asynchronous development in JavaScript
Promises - The Unsung Heroes ofJavaScript
Async all around us (promises)
CommitConf 2018 - Going Async With Kotlin
Seastar Summit 2019: Past and future of futures
The art of concurrent programming
Mobile Application Development class 008
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Tartificialntelligence_presentation.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
August Patch Tuesday
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
Tartificialntelligence_presentation.pptx
Assigned Numbers - 2025 - Bluetooth® Document
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MIND Revenue Release Quarter 2 2025 Press Release
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25-Week II
August Patch Tuesday
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Ad

Promise on iOs