Instantly share code, notes, and snippets.

Embed
What would you like to do?
RxJS: Promise Observable Similarity
// example of a promise
const deferred = new Promise((resolve, reject) => {
setTimeout(function() {
resolve('Promise resolved.')
}, 2000)
})
deferred.then(function resolved(data) {
console.log(data)
}, function rejected(err) {
console.log(err)
})
// example of the same using obsevable
const defferedObservable = Rx.Observable.of('Observable resolved.')
.delay(2000)
defferedObservable.subscribe(function emitted(data) {
console.log(data)
}, function rejected(err) {
console.log(errr)
})
// Not very different! Eh??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment