Because someBlockingMethodTofetchDBRecords
is not lazy and you hand its result to an Observable
after.
Yes, Observable
s are lazy by default thus they don't perform their subscription action until there is an Observer
subscribing. However, from
's subscription action is to iterate over an existing sequence and emit its values. That sequence was handed, and thus created, outside of Observable
.
Therefore, if you need to have the sequence itself to be created only when there is an Observer
for it, its creation has to be part of the subscription action, for which defer
is an operator to make that happen.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…