Observable using defer
Observable normally gets created once the code executes, Observable using defer , defers the creation of Observable. It waits till a subscription is done.
Below are main property of Observable using defer.
- Creates new observable every time on subscription
- No Observable is created until subscription
Below is the code showing Observable using defer
Here intentionally we are subscribing 2 times to show that each time Observable is created. You can also see that defer is taking fromIterable to create the observable. This will stop creating defer until we subscribe. Once subscribed Observable.fromInterable code will be invoked
No Comments Yet