Async programming
With Observable
Seydou N Ba

@douxsey03
Programme
• Async programming késaco ?

• How we do it in javascript ?

- callback

- Promise: then / async/await

• Observable to the rescue.

• Iterator <==> Observer
Async programming
In other Land
blocking (I/O)
In other land
special syntax
How JS Does Async things!
Example in JS
But why ?
• Why It is different (can not use data just after)

• Why not sequential
Because…
• JS is single thread

• Designated first for client side

- Should do others thing

- and take care of the user also

• Non Blocking model
Asynchronous Issues
• Complex State

• Error handling

• Memory Leaks

• Race Conditions

• Risk Of retry
Callbacks
Hum..But..But
Callback HELL
Callback not so great
• Callback Hell

• Error handling - kinda suicidal

• No control
What about
PROMISE
More complex One
Promise are not perfect also
• Callback Hell

• Error handling - kinda suicidal

• No control

• Only resolve once (not suitable for events)

• Not cancellable

• Always Asynchrone
Observables
Definition
For me…
• Observable = data + time (kinda promise but
continuously)

• Hum sounds familiar: Streams is a sequence of data
elements made available over time. (Wikipedia)

•
Streams Emit…
• Values

• Error

• Complete Signal (end of the stream)
Streamable in JS
• DOM Events (click, mouseover, mouse-down, keyup,..)

• Animations

• WebSockets

• Http Requests

• …
What else..
• They need an observer.

• They are lazy

• They are just function

• They link producers to consumers
Observer
• Literal JS Object that implements:

• next function

• error: function

• complete function
Example observer
Just Function
• They are just function
Example of observable
Resume
Some useful operator
• throttle

• debounce

• map

• filter

• takeUntil
Iterator
<==>
Observable
Iterators ???
• Literal JS object that implements: 

• a next function that should return an object with

- done

- value

• that sounds so familiar
As we said before…
lets try custom
observable
Ah!!!
thanks,
END

Async programming with Observable