Home:ALL Converter>rxjs created observable timeout always errors

rxjs created observable timeout always errors

Ask Time:2017-10-20T22:05:02         Author:hesxenon

Json Formatter

ok, so now I'm really puzzled. Executing the following code

const created = Rx.Observable.create(observer => {
  observer.next(42)
})
const ofd = Rx.Observable.of(42)

const createSub = name => [
  val => console.log(`${name} received ${val}`),
  error => console.log(`${name} threw ${error.constructor.name}`)
]

created
  .timeout(100)
  .subscribe(
    ...createSub('created')
  )

ofd
  .timeout(100)
  .subscribe(
    ...createSub('ofd')
  )

Prints

"created received 42"
"ofd received 42"
"created threw TimeoutError"

I don't understand this at all, why does the created Observable error even though it emits a value but the ofd Observable does not??

Using RxJS 5, problem occurs with 5.0.3 in jsbin.com and 5.4.3 in my app.

(Note: This happens with subjects too, which led me to create this example)

Author:hesxenon,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46850852/rxjs-created-observable-timeout-always-errors
yy