Closed mlegenhausen closed 4 years ago
@mlegenhausen Just out of curiosity, is there a reason fromIO
uses asynchronous context?
For example, it could have been implemented like so:
export function fromIO<A>(io: IO<A>): Observable<A> {
return defer(() => rxOf(io()))
}
Is there an advantage to using async
here instead? Is it conceptually more correct?
Is there an advantage to using async here instead? Is it conceptually more correct?
Don't think so. I think I chose async
cause it was more inline with the fromTask
implementation. Without knowing the internals (and the rxjs documentation isn't there of any help) it could be that your implementation could save one event loop iteration when calling the IO
but this is only a guess.
I think you're right. fromIO
wasn't working for my game engine's spec b/c TestScheduler doesn't work in async contexts, but when I rolled my own fromSyncIO it worked just fine.
Could this be a desired PR? It does seem mildly more correct since you can raise into asynchronous context with observeOn(AsyncScheduler) but you can't go back to synchronous context from async.
It probably doesn't matter for most use cases though, especially since the function is so simple, and I certainly don't mind using my own fromSyncIO
.
Could this be a desired PR?
Yes definitely.
Thanks @mlegenhausen