loading...

re: Callbacks vs Promises in JavaScript VIEW POST

FULL DISCUSSION
 
const getMoneyBack = (money: number): Observable<number> => {
  return new Observable(subscriber => {
    if (typeof money !== 'number') {
      subscriber.error(new Error('money is not a number'))
  } else {
    subscriber.next(money)
    subscriber.complete()
  }
}

const moneySubscription: Subscription = getMoneyBack(1200)
  .subscribe({
    next: money => console.log(money),
    error: error => console.log(error)
  })

moneySubscription.unsubscribe()
code of conduct - report abuse