Search code examples
javaandroidfunctionchainingchain

How to stop chain method calls?


I have code in which there are number of functions are executing one by one e.g.

void a(){
   //do some stuff
   b();
}
void b(){
   // do something
   c();
}
void c(){
   // do something
}

now at given time I want to stop this chain irrespective to which function is in execution right now. I have stop this chain processs at given time. how can do it in android(java)?


Solution

  • You can achieve it by this way

    boolean stop = false;
    
    void a(){
        //do some stuff
        if(!stop)
        b();
    }
    void b(){
        // do something
        if(!stop)
        c();
    }
    void c(){
        // do something
        if(!stop){
    
        }
    }
    
    
    void stopCallingMethod(){
        stop = true;
    }
    

    if you want to stop the methods a, b, c you can call stopCallingMethod() method