I am implementing an interface.
I have two functions that I have to implement A and B. A checks the file is not corrupt and return then B processes the file and returns. after B return function C runs, I have no control over C as I am just implementing A and B.
The problem is that B takes a long time to run and C needs it return value to run. Ideally I would split B into B and D and put all the stuff that C dose not need to run into D. As this is impossible I want to know if it is possible to return a value from B so C can run but afterwards then have B run more code.
C cannot be called from B.
Amust callBandCYou wantBto do some processing,Cto be called andBto continue processing.The simplest approach is to have
Acalled a method onBwhich opens the file and does some processing, and leaves anything open which is need later.AcallsCand then calls another method onBwhich finishes the processing. This meansBmust know when to stop and return soCcan be called.The way around this is to use a listener interface below.
This way
Bhas no idea whenCwill be called.You can implement a listener interface which you pass to the function and it can “return” multiple values. However once a function actually
returns it is no longer running.This function can run in another thread or the same thread.
put another way instead of doing something like
you can do