promise on ios
TRANSCRIPT
Future/Promise on iOS
Thinh VoXuan Summer 2016
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
• Synchronous vs Asynchronous
Not TodayFuture/Promise on iOS
3
Callback hell & Another problemsFuture/Promise on iOS
4
Callback hell & Another problemsFuture/Promise on iOS
5
Callback hell & Another problemsFuture/Promise on iOS
6
Callback hell & Another problemsFuture/Promise on iOS
7
How could I call 3 requests on same times?
Callback hell & Another problemsFuture/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 ? - fulfilledFuture/Promise on iOS
10
fulfilled could be•Value•Object•Another Promise
What is promise ? - rejectedFuture/Promise on iOS
11
rejected could be•Error
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.
Chaining tasks patternFuture/Promise on iOS
13
Chaining tasks patternFuture/Promise on iOS
14
Chaining tasks patternFuture/Promise on iOS
15
Chaining tasks pattern - continueWithFuture/Promise on iOS
16
Chaining tasks patternFuture/Promise on iOS
17
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.
Parallel tasks patternFuture/Promise on iOS
19
Parallel tasks pattern - whenAllFuture/Promise on iOS
20
Parallel tasks pattern - whenAllResultFuture/Promise on iOS
21
Parallel tasks pattern – whenAnyFuture/Promise on iOS
22
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
• How to create Promise from Asynchronous function
• How to create Promise from Synchronous function
BoltFrameworkFuture/Promise on iOS
24
BoltFramework – Create PromiseFuture/Promise on iOS
25
BoltFramework/Bolt-Swift
BoltFramework – Create PromiseFuture/Promise on iOS
26
BoltFramework/Bolt-ObjC
• Readable code• Testable code• Component task• Re-useable code
AdvantagesFuture/Promise on iOS
27
Chaining tasks pattern - continueOnSuccessWith
Future/Promise on iOS
28
ReferencesFuture/Promise on iOS
29
• https://github.com/BoltsFramework/Bolts-Swift
• https://github.com/BoltsFramework/Bolts-ObjC
• http://www.slideshare.net/NicholasvandeWalle/promisesdraft
Q&AFuture/Promise on iOS
30
Thank youFuture/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
whoamiFuture/Promise on iOS
32