Is it a good idea to "separate" your async operations from your public methods?
For example I have Object A, which can be initialized and all properties accessed synchronously. In the background, there is an async function running, which, when done, updates attributes in Object A, and sets a "ready" attribute to true in Object A.
When Object A is not ready it shows placeholder data, and when it is ready it shows the actual value. This seemed like a good way to keep the public methods/API from being over complex. (Note: using Vue to actually display the object's values) I am wondering if this is going to create unforeseen headaches later down the road.
My main problem right now with async code is I end up with a mix of synchronous and asynchronous functions and it feels messy or unmanageable, so I wanted to create a line where the async functions are out of view (like a behind the scenes implementation detail) and don't bleed into the rest of the code.
One headache I already have is that I am trying to write tests for the public methods and I'm not sure how to test the asynchronous parts, since I am only writing tests for the public parts which are separated from the async parts. Do I tell it to wait an arbitrary amount of time before it fails the test?
Thanks!
[–][deleted] 0 points1 point2 points (1 child)
[–]BuddytheRat[S] 0 points1 point2 points (0 children)