Cold vs Hot data source

Maybe you heard of it, maybe you don’t. Hot or cold data sources. Let me explain briefly what it is and how you should use it.

The general idea is that hot data sources are active even outside when it is called and cold data sources is not doing anything before it is called and it will not do anything afterwards.


When you call computeAsync you get a promise to deliver a value in the future. Now you have to be careful not to lose a reference to this future, because this future is effectively a resource, where you must wait for it or cancel it if its value is no longer needed.

This is known as a hot data source. Unlike a regular function, that is active only during a call to it, a hot source is active even outside of the call to the corresponding function — it might have been active in background before the function was even called, and can still be active after the function was called, like we see here.

This computeAsync function below is cold — it is not doing anything before it is called and it will not do anything after returning a value. There is no need to worry about accidentally losing a reference to the working background operation 

Add a Comment

Your email address will not be published.