I have method A that runs on thread #1.
I also have method B that runs on thread #2.
Method A writes to a shared object a function C (method that receives an object value and returns a Boolean value) that should be executed on some event via method B. (method B is a TCP listener method that runs forever)
I wish that method A will wait until that event occurs AND the C is finished. Currently its implemented with a Sleep based for loop (with timeout and such).
Let me make myself more clear, the flow is like this:
Method B (on thread #2): while(true) { process data, if data has x then someFunc(..) }
Method A (on thread #1): someFunc = (obj) => {...};
wait until someFunc is executed by B & is finished;
do more stuff
Whats the smartest way of achieving this?