Hi assuming following code
import { Signal } from '@angular/core';
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
const result = toSignal(toObservable(signal(10)))
console.log(result()) // does log undefined instead of 10
I would assume that result()
will return 10
instead of undefined
.
However it seems like I'm missing something but I dunno what.
This is an effect you're seeing is due to the current implementation of toObservable. If you look at the implementation you'll see that the emissions are created inside of an effect. Effects always run asynchronously during the change detection cycle. So you can't count on them running immediately.
If you think about it, this is the best that could be done. For example, it could've performed an initial emission before the watcher (subject.next(source())
), but...
So take it for granted that the first emission by an observable created from toObservable will be delayed.