promise on ios
TRANSCRIPT
![Page 1: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/1.jpg)
Future/Promise on iOS
Thinh VoXuan Summer 2016
![Page 2: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/2.jpg)
1. Callback hell & Another problem2. What is promise ?3. Chaining tasks pattern4. Parallel tasks pattern5. Errors handler6. Example with Bolt Framework7. Advantages
AgendaFuture/Promise on iOS
2
![Page 3: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/3.jpg)
• Synchronous vs Asynchronous
Not TodayFuture/Promise on iOS
3
![Page 4: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/4.jpg)
Callback hell & Another problemsFuture/Promise on iOS
4
![Page 5: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/5.jpg)
Callback hell & Another problemsFuture/Promise on iOS
5
![Page 6: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/6.jpg)
Callback hell & Another problemsFuture/Promise on iOS
6
![Page 7: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/7.jpg)
Callback hell & Another problemsFuture/Promise on iOS
7
How could I call 3 requests on same times?
![Page 8: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/8.jpg)
Callback hell & Another problemsFuture/Promise on iOS
8
Hard to understand and follow the logic ?
What happen when 1 request has error?
![Page 9: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/9.jpg)
What is promise ?Future/Promise on iOS
9
• Deferred State• pending
• Settled State• fulfilled• rejected
![Page 10: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/10.jpg)
What is promise ? - fulfilledFuture/Promise on iOS
10
fulfilled could be•Value•Object•Another Promise
![Page 11: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/11.jpg)
What is promise ? - rejectedFuture/Promise on iOS
11
rejected could be•Error
![Page 12: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/12.jpg)
Chaining tasks patternFuture/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.
![Page 13: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/13.jpg)
Chaining tasks patternFuture/Promise on iOS
13
![Page 14: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/14.jpg)
Chaining tasks patternFuture/Promise on iOS
14
![Page 15: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/15.jpg)
Chaining tasks patternFuture/Promise on iOS
15
![Page 16: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/16.jpg)
Chaining tasks pattern - continueWithFuture/Promise on iOS
16
![Page 17: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/17.jpg)
Chaining tasks patternFuture/Promise on iOS
17
![Page 18: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/18.jpg)
Parallel tasks patternFuture/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.
![Page 19: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/19.jpg)
Parallel tasks patternFuture/Promise on iOS
19
![Page 20: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/20.jpg)
Parallel tasks pattern - whenAllFuture/Promise on iOS
20
![Page 21: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/21.jpg)
Parallel tasks pattern - whenAllResultFuture/Promise on iOS
21
![Page 22: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/22.jpg)
Parallel tasks pattern – whenAnyFuture/Promise on iOS
22
![Page 23: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/23.jpg)
Could only go with tasks on function•continueWith•continueOnErrorWith
If error occurs next task on continueOnSuccessWith will never run
Errors handlerFuture/Promise on iOS
23
![Page 24: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/24.jpg)
• How to create Promise from Asynchronous function
• How to create Promise from Synchronous function
BoltFrameworkFuture/Promise on iOS
24
![Page 25: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/25.jpg)
BoltFramework – Create PromiseFuture/Promise on iOS
25
BoltFramework/Bolt-Swift
![Page 26: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/26.jpg)
BoltFramework – Create PromiseFuture/Promise on iOS
26
BoltFramework/Bolt-ObjC
![Page 27: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/27.jpg)
• Readable code• Testable code• Component task• Re-useable code
AdvantagesFuture/Promise on iOS
27
![Page 28: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/28.jpg)
Chaining tasks pattern - continueOnSuccessWith
Future/Promise on iOS
28
![Page 29: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/29.jpg)
ReferencesFuture/Promise on iOS
29
• https://github.com/BoltsFramework/Bolts-Swift
• https://github.com/BoltsFramework/Bolts-ObjC
• http://www.slideshare.net/NicholasvandeWalle/promisesdraft
![Page 30: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/30.jpg)
Q&AFuture/Promise on iOS
30
![Page 31: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/31.jpg)
Thank youFuture/Promise on iOS
31
![Page 32: Promise on iOs](https://reader035.vdocument.in/reader035/viewer/2022070602/5874d8661a28abd05f8b6081/html5/thumbnails/32.jpg)
• 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
whoamiFuture/Promise on iOS
32