promise on ios

32
Future/Promise on iOS Thinh VoXuan Summer 2016

Upload: thinh-voxuan

Post on 15-Apr-2017

335 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Promise on iOs

Future/Promise on iOS

Thinh VoXuan Summer 2016

Page 2: Promise on iOs

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

• Synchronous vs Asynchronous

Not TodayFuture/Promise on iOS

3

Page 4: Promise on iOs

Callback hell & Another problemsFuture/Promise on iOS

4

Page 5: Promise on iOs

Callback hell & Another problemsFuture/Promise on iOS

5

Page 6: Promise on iOs

Callback hell & Another problemsFuture/Promise on iOS

6

Page 7: Promise on iOs

Callback hell & Another problemsFuture/Promise on iOS

7

How could I call 3 requests on same times?

Page 8: Promise on iOs

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

What is promise ?Future/Promise on iOS

9

• Deferred State• pending

• Settled State• fulfilled• rejected

Page 10: Promise on iOs

What is promise ? - fulfilledFuture/Promise on iOS

10

fulfilled could be•Value•Object•Another Promise

Page 11: Promise on iOs

What is promise ? - rejectedFuture/Promise on iOS

11

rejected could be•Error

Page 12: Promise on iOs

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

Chaining tasks patternFuture/Promise on iOS

13

Page 14: Promise on iOs

Chaining tasks patternFuture/Promise on iOS

14

Page 15: Promise on iOs

Chaining tasks patternFuture/Promise on iOS

15

Page 16: Promise on iOs

Chaining tasks pattern - continueWithFuture/Promise on iOS

16

Page 17: Promise on iOs

Chaining tasks patternFuture/Promise on iOS

17

Page 18: Promise on iOs

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

Parallel tasks patternFuture/Promise on iOS

19

Page 20: Promise on iOs

Parallel tasks pattern - whenAllFuture/Promise on iOS

20

Page 21: Promise on iOs

Parallel tasks pattern - whenAllResultFuture/Promise on iOS

21

Page 22: Promise on iOs

Parallel tasks pattern – whenAnyFuture/Promise on iOS

22

Page 23: Promise on iOs

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

• How to create Promise from Asynchronous function

• How to create Promise from Synchronous function

BoltFrameworkFuture/Promise on iOS

24

Page 25: Promise on iOs

BoltFramework – Create PromiseFuture/Promise on iOS

25

BoltFramework/Bolt-Swift

Page 26: Promise on iOs

BoltFramework – Create PromiseFuture/Promise on iOS

26

BoltFramework/Bolt-ObjC

Page 27: Promise on iOs

• Readable code• Testable code• Component task• Re-useable code

AdvantagesFuture/Promise on iOS

27

Page 28: Promise on iOs

Chaining tasks pattern - continueOnSuccessWith

Future/Promise on iOS

28

Page 30: Promise on iOs

Q&AFuture/Promise on iOS

30

Page 31: Promise on iOs

Thank youFuture/Promise on iOS

31

Page 32: Promise on iOs

• 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