I have a long running method that I wish to be able to update something else everytime a step is concluded.
class A {
private B b;
callLongRunning() {
b.longRunningMethod()
}
class B {
longRunningMethod(){
doSomethingThatTakesAWhile();
doSomethingThatTakesAWhile();
doSomethingThatTakesAWhile();
doSomethingThatTakesAWhile();
}
After each call to B.doSomethingThatTakesAWhile() I wish to "return" a message so class A can update a registry with some info.
I am looking as Rx.Observables but I am not understanding how to use it in this scenario.
I wish to do something like this:
class A {
private B b;
callLongRunning() {
someSpecialStateObject.onPush(state => updateDb(state));
someSpecialStateObject.onFinish(state => doSomethingElse(state));
b.longRunningMethod(someSpecialStateObject)
//continue only after it all ends
}
class B {
longRunningMethod(someSpecialStateObject){
doSomethingThatTakesAWhile();
someSpecialStateObject.push("finished step 1");
doSomethingThatTakesAWhile();
someSpecialStateObject.push("finished step 2");
doSomethingThatTakesAWhile();
someSpecialStateObject.push("finished step 3");
doSomethingThatTakesAWhile();
someSpecialStateObject.finish("finished everything");
}